Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(webv2): shuffle button for numeric fields in the linear view

Josh Corbett8cee5499bc4a
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index ef6de715b1..83ffdbea23 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -267,6 +267,7 @@
"decrementDescription": "Use successive seeds, decreasing by 1."
},
"newSeed": "New seed",
+ "shuffle": "Shuffle",
"seedNextBatch": "Next batch: {{seed}}",
"seedNextBatchRange": "Next batch: {{first}} → {{last}}",
"decreaseValue": "Decrease value",
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/document.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/document.test.ts
index 687349fa6b..1f1a6ca160 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/document.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/document.test.ts
@@ -305,6 +305,16 @@ describe('projectGraphReducer', () => {
const updatedField = next.form.elements[field?.id ?? ''];
expect(updatedField?.type === 'node-field' && updatedField.data.showDescription).toBe(true);
+
+ next = projectGraphReducer(next, {
+ elementId: field?.id ?? '',
+ showShuffle: true,
+ type: 'setNodeFieldShowShuffle',
+ });
+
+ const shuffledField = next.form.elements[field?.id ?? ''];
+
+ expect(shuffledField?.type === 'node-field' && shuffledField.data.showShuffle).toBe(true);
});
it('updates metadata via patch', () => {
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/document.ts b/invokeai/frontend/webv2/src/features/workflow/core/document.ts
index d073810656..8d7f315116 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/document.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/document.ts
@@ -4,6 +4,7 @@ import type {
ContainerFormElement,
FieldIdentifier,
InvocationTemplate,
+ NodeFieldFormElement,
ProjectGraphState,
WorkflowCurrentImageNode,
WorkflowConnectorNode,
@@ -304,9 +305,9 @@ export type ProjectGraphAction =
/** Moves stepping-mode seeds past a queued submission; each field is fenced on the value and mode it was planned from. */
| { type: 'advanceSeedFields'; advances: readonly WorkflowSeedFieldAdvance[] }
| { type: 'addEdge'; edge: WorkflowEdge }
- | { type: 'removeEdges'; edgeIds: string[] }
/** Replaces `edgeId` with `edge` as one undoable step (dragging an edge end to a new handle). */
| { type: 'reconnectEdge'; edgeId: string; edge: WorkflowEdge }
+ | { type: 'removeEdges'; edgeIds: string[] }
| { type: 'exposeField'; fieldIdentifier: FieldIdentifier }
| { type: 'unexposeField'; fieldIdentifier: FieldIdentifier }
| { type: 'removeFormElement'; elementId: string }
@@ -320,14 +321,15 @@ export type ProjectGraphAction =
}
| { type: 'setFormElementContent'; elementId: string; content: string }
| { type: 'setNodeFieldShowDescription'; elementId: string; showDescription: boolean }
+ | { type: 'setNodeFieldShowShuffle'; elementId: string; showShuffle: boolean }
| { type: 'setContainerLayout'; elementId: string; layout: 'row' | 'column' }
| { type: 'setMetadata'; patch: Partial<WorkflowMetadata> };
const undoLabels: Partial<Record<ProjectGraphAction['type'], string>> = {
addEdge: 'Connect workflow fields',
+ reconnectEdge: 'Reconnect workflow fields',
addFormElement: 'Edit workflow form',
addGraphElements: 'Paste workflow nodes',
- reconnectEdge: 'Reconnect workflow fields',
addNode: 'Add workflow node',
addNodeAndEdge: 'Add workflow node',
exposeField: 'Expose workflow field',
@@ -338,6 +340,7 @@ const undoLabels: Partial<Record<ProjectGraphAction['type'], string>> = {
removeNodes: 'Delete workflow nodes',
setContainerLayout: 'Edit workflow form',
setNodeFieldShowDescription: 'Edit workflow form',
+ setNodeFieldShowShuffle: 'Edit workflow form',
unexposeField: 'Remove workflow field from form',
};
@@ -374,6 +377,26 @@ const setFieldInstance = (
};
});
+const patchNodeFieldElement = (
+ document: ProjectGraphState,
+ elementId: string,
+ patch: Partial<Omit<NodeFieldFormElement['data'], 'fieldIdentifier'>>
+): ProjectGraphState => {
+ const element = document.form.elements[elementId];
+
+ if (!element || element.type !== 'node-field') {
+ return document;
+ }
+
+ return {
+ ...document,
+ form: {
+ ...document.form,
+ elements: { ...document.form.elements, [element.id]: { ...element, data: { ...element.data, ...patch } } },
+ },
+ };
+};
+
const addEdgeToDocument = (document: ProjectGraphState, edge: WorkflowEdge): ProjectGraphState => {
// A non-collect input holds at most one connection; connecting replaces it.
const targetNode = document.nodes.find((node) => node.id === edge.target);
@@ -560,6 +583,16 @@ const applyProjectGraphAction = (document: ProjectGraphState, action: ProjectGra
case 'addEdge': {
return addEdgeToDocument(document, action.edge);
}
+ case 'reconnectEdge': {
+ if (!document.edges.some((edge) => edge.id === action.edgeId)) {
+ return document;
+ }
+
+ return addEdgeToDocument(
+ { ...document, edges: document.edges.filter((edge) => edge.id !== action.edgeId) },
+ action.edge
+ );
+ }
case 'removeEdges': {
const removedEdgeIds = new Set(action.edgeIds);
@@ -577,22 +610,12 @@ const applyProjectGraphAction = (document: ProjectGraphState, action: ProjectGra
return {
...document,
form: appendToRoot(document.form, {
- data: { fieldIdentifier: { ...action.fieldIdentifier }, showDescription: false },
+ data: { fieldIdentifier: { ...action.fieldIdentifier }, showDescription: false, showShuffle: false },
id: createWorkflowId('node-field'),
type: 'node-field',
}),
};
}
- case 'reconnectEdge': {
- if (!document.edges.some((edge) => edge.id === action.edgeId)) {
- return document;
- }
-
- return addEdgeToDocument(
- { ...document, edges: document.edges.filter((edge) => edge.id !== action.edgeId) },
- action.edge
- );
- }
case 'unexposeField': {
const element = findNodeFieldElement(document.form, action.fieldIdentifier);
@@ -670,22 +693,16 @@ const applyProjectGraphAction = (document: ProjectGraphState, action: ProjectGra
};
}
case 'setNodeFieldShowDescription': {
- const element = document.form.elements[action.elementId];
-
- if (!element || element.type !== 'node-field') {
- return document;
- }
+ return patchNodeFieldElement(document, action.elementId, { showDescription: action.showDescription });
+ }
+ case 'setNodeFieldShowShuffle': {
+ const settings = document.form.elements[action.elementId];
+ const legacySettings = settings?.type === 'node-field' ? settings.data.settings : undefined;
- return {
- ...document,
- form: {
- ...document.form,
- elements: {
- ...document.form.elements,
- [element.id]: { ...element, data: { ...element.data, showDescription: action.showDescription } },
- },
- },
- };
+ return patchNodeFieldElement(document, action.elementId, {
+ showShuffle: action.showShuffle,
+ ...(legacySettings ? { settings: { ...legacySettings, showShuffle: action.showShuffle } } : {}),
+ });
}
case 'setMetadata': {
return { ...document, ...action.patch };
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts
index 5db37d6aad..be8bd869b8 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/fields.test.ts
@@ -9,6 +9,8 @@ import {
isModelFieldType,
isWorkflowFieldValueValid,
toLoraFieldCollectionList,
+ getRandomWorkflowFieldValue,
+ isShuffleableField,
} from './fields';
const single = (name: string): FieldType => ({ batch: false, cardinality: 'SINGLE', name });
@@ -189,3 +191,49 @@ describe('workflow field type helpers', () => {
expect(isModelFieldType(single('ImageField'))).toBe(false);
});
});
+
+describe('getRandomWorkflowFieldValue', () => {
+ it('stays inside the template bounds and snaps to the step', () => {
+ const template = input({ maximum: 10, minimum: 2, multipleOf: 2, type: single('IntegerField') });
+
+ expect(getRandomWorkflowFieldValue(template, () => 0)).toBe(2);
+ expect(getRandomWorkflowFieldValue(template, () => 0.999)).toBe(10);
+ expect(getRandomWorkflowFieldValue(template, () => 0.55)).toBe(6);
+
+ const odd = input({ maximum: 9, minimum: 0, multipleOf: 2, type: single('IntegerField') });
+
+ expect(getRandomWorkflowFieldValue(odd, () => 0.999)).toBe(8);
+
+ const decimal = input({ maximum: 1, minimum: 0, multipleOf: 0.1, type: single('FloatField') });
+
+ expect(getRandomWorkflowFieldValue(decimal, () => 0.3)).toBe(0.3);
+ });
+
+ it('respects exclusive bounds for integers and keeps floats unrounded', () => {
+ const integer = input({ exclusiveMaximum: 5, exclusiveMinimum: 0, type: single('IntegerField') });
+
+ expect(getRandomWorkflowFieldValue(integer, () => 0)).toBe(1);
+ expect(getRandomWorkflowFieldValue(integer, () => 0.999)).toBe(4);
+
+ const float = input({ maximum: 1, minimum: 0, type: single('FloatField') });
+
+ expect(getRandomWorkflowFieldValue(float, () => 0.25)).toBe(0.25);
+
+ const steppedExclusive = input({
+ exclusiveMaximum: 1,
+ exclusiveMinimum: 0,
+ multipleOf: 0.5,
+ type: single('FloatField'),
+ });
+
+ expect(getRandomWorkflowFieldValue(steppedExclusive, () => 0)).toBe(0.5);
+ expect(getRandomWorkflowFieldValue(steppedExclusive, () => 0.999)).toBe(0.5);
+ });
+
+ it('shuffles only direct numeric fields', () => {
+ expect(isShuffleableField(input({ type: single('IntegerField') }))).toBe(true);
+ expect(isShuffleableField(input({ type: single('FloatField') }))).toBe(true);
+ expect(isShuffleableField(input({ input: 'connection', type: single('IntegerField') }))).toBe(false);
+ expect(isShuffleableField(input())).toBe(false);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/fields.ts b/invokeai/frontend/webv2/src/features/workflow/core/fields.ts
index 2bf653f0ed..595ebcf63c 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/fields.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/fields.ts
@@ -1,3 +1,5 @@
+import { SEED_MAX } from '@platform/core/seed';
+
import type { FieldInputTemplate, FieldType } from './types';
/**
@@ -50,6 +52,49 @@ export const cloneWorkflowFieldDefault = (template: FieldInputTemplate): unknown
export const isWorkflowFieldValueDefault = (template: FieldInputTemplate, value: unknown): boolean => {
if (value === template.default) {
+/** Numeric fields whose linear-form element can show a randomize button. */
+export const isShuffleableField = (template: FieldInputTemplate): boolean =>
+ (template.type.name === 'IntegerField' || template.type.name === 'FloatField') && isDirectInputField(template);
+
+const countDecimals = (value: number): number => {
+ const [, fraction = ''] = String(value).split('.');
+
+ return fraction.length;
+};
+
+/** A random value inside the template's bounds, snapped to its step; unbounded ends default to 0…SEED_MAX. */
+export const getRandomWorkflowFieldValue = (template: FieldInputTemplate, random = Math.random): number => {
+ const isInteger = template.type.name === 'IntegerField';
+ const step = template.multipleOf ?? (isInteger ? 1 : 0);
+ const { exclusiveMaximum, exclusiveMinimum, maximum, minimum } = template;
+
+ if (step <= 0) {
+ const min = minimum ?? exclusiveMinimum ?? 0;
+ const max = maximum ?? exclusiveMaximum ?? SEED_MAX;
+
+ return min + random() * (max - min);
+ }
+
+ // Draw among the step multiples that lie inside the bounds (exclusive ends excluded), so the
+ // result is always valid.
+ const decimals = countDecimals(step);
+ const first =
+ minimum !== null
+ ? Math.ceil(minimum / step)
+ : exclusiveMinimum !== null
+ ? Math.floor(exclusiveMinimum / step) + 1
+ : 0;
+ const last =
+ maximum !== null
+ ? Math.floor(maximum / step)
+ : exclusiveMaximum !== null
+ ? Math.ceil(exclusiveMaximum / step) - 1
+ : Math.floor(SEED_MAX / step);
+ const index = first + Math.floor(random() * (last - first + 1));
+
+ return Number((Math.min(last, index) * step).toFixed(decimals));
+};
+
return true;
}
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/types.ts b/invokeai/frontend/webv2/src/features/workflow/core/types.ts
index 0e4d503f02..149f0ef5fc 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/types.ts
@@ -193,6 +193,10 @@ export interface NodeFieldFormElement {
data: {
fieldIdentifier: FieldIdentifier;
showDescription: boolean;
+ /** Shows a randomize button beside numeric fields in the linear view. */
+ showShuffle: boolean;
+ /** The legacy editor's per-element settings, preserved verbatim; `showShuffle` is mirrored into it. */
+ settings?: Record<string, unknown>;
};
}
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
index 11734fec25..b744173906 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
@@ -125,6 +125,64 @@ describe('workflow JSON round-trip', () => {
});
describe('parseWorkflowJson tolerance', () => {
+ it('reads the legacy per-element shuffle setting and keeps the settings bag for the legacy editor', () => {
+ const { document, warnings } = parseWorkflowJson({
+ edges: [],
+ form: {
+ elements: {
+ root: { data: { children: ['f1'], layout: 'column' }, id: 'root', type: 'container' },
+ f1: {
+ data: {
+ fieldIdentifier: { fieldName: 'steps', nodeId: 'n1' },
+ settings: { component: 'number-input', showShuffle: true },
+ },
+ id: 'f1',
+ parentId: 'root',
+ type: 'node-field',
+ },
+ },
+ rootElementId: 'root',
+ },
+ name: 'Legacy Shuffle',
+ nodes: [
+ {
+ data: { id: 'n1', inputs: { steps: { label: '', name: 'steps', value: 20 } }, type: 'noise' },
+ id: 'n1',
+ position: { x: 0, y: 0 },
+ type: 'invocation',
+ },
+ ],
+ version: '1.0.0',
+ });
+
+ expect(warnings).toEqual([]);
+
+ const field = document.form.elements.f1;
+
+ expect(field?.type === 'node-field' && field.data).toEqual({
+ fieldIdentifier: { fieldName: 'steps', nodeId: 'n1' },
+ settings: { component: 'number-input', showShuffle: true },
+ showDescription: false,
+ showShuffle: true,
+ });
+
+ const toggled = projectGraphReducer(document, {
+ elementId: 'f1',
+ showShuffle: false,
+ type: 'setNodeFieldShowShuffle',
+ });
+ const toggledField = toggled.form.elements.f1;
+ const serialized = serializeWorkflowJson(toggled) as { form: { elements: Record<string, { data: unknown }> } };
+
+ expect(toggledField?.type === 'node-field' && toggledField.data.settings).toEqual({
+ component: 'number-input',
+ showShuffle: false,
+ });
+ expect(serialized.form.elements.f1?.data).toMatchObject({
+ settings: { component: 'number-input', showShuffle: false },
+ });
+ });
+
it('migrates pre-form exposedFields into form elements', () => {
const { document, warnings } = parseWorkflowJson({
edges: [],
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
index 8d4952aa09..82be22fd2d 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
@@ -104,10 +104,20 @@ const zFormElement = z.discriminatedUnion('type', [
type: z.literal('container'),
}),
z.object({
- data: z.looseObject({
- fieldIdentifier: zFieldIdentifier,
- showDescription: z.boolean().catch(false),
- }),
+ data: z
+ .looseObject({
+ fieldIdentifier: zFieldIdentifier,
+ showDescription: z.boolean().catch(false),
+ showShuffle: z.boolean().optional(),
+ // The legacy editor keeps its per-element settings (component, bounds, shuffle) here; they
+ // are carried through untouched so a workflow saved from webv2 still opens the same there.
+ settings: z.looseObject({ showShuffle: z.boolean().optional() }).optional(),
+ })
+ .transform(({ settings, showShuffle, ...data }) => ({
+ ...data,
+ ...(settings ? { settings } : {}),
+ showShuffle: showShuffle ?? settings?.showShuffle ?? false,
+ })),
id: z.string(),
parentId: z.string().optional(),
type: z.literal('node-field'),
@@ -198,7 +208,7 @@ const parseForm = (
if (root?.type === 'container') {
for (const fieldIdentifier of exposedFields) {
const element: WorkflowFormElement = {
- data: { fieldIdentifier, showDescription: false },
+ data: { fieldIdentifier, showDescription: false, showShuffle: false },
id: createWorkflowId('node-field'),
parentId: root.id,
type: 'node-field',
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/flowAdapters.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/editor/flowAdapters.test.ts
index 1ebd78293e..c8dc983b77 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/flowAdapters.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/flowAdapters.test.ts
@@ -172,7 +172,7 @@ describe('flowAdapters identity preservation', () => {
elements: {
...doc.form.elements,
'field-1': {
- data: { fieldIdentifier: { fieldName: 'a', nodeId: 'b' }, showDescription: false },
+ data: { fieldIdentifier: { fieldName: 'a', nodeId: 'b' }, showDescription: false, showShuffle: false },
id: 'field-1',
parentId: doc.form.rootElementId,
type: 'node-field' as const,
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx
index 7577a1bba9..9055861378 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/FormBuilderTab.tsx
@@ -26,16 +26,31 @@ import {
type WorkflowForm,
type WorkflowFormElement,
} from '@features/workflow/contracts';
+import { isSeedInputField } from '@features/workflow/graph';
import { useInvocationTemplatesSelector, type InvocationTemplatesSnapshot } from '@features/workflow/react';
import { requestNodeSelection, workflowSelectionStore } from '@features/workflow/ui/editor/selectionStore';
import { FieldDescriptionPopover } from '@features/workflow/ui/fields/FieldDescriptionPopover';
import { getWorkflowNodeChromeProps } from '@features/workflow/ui/nodeChrome';
import { useProjectGraphCommands } from '@features/workflow/ui/useProjectGraphCommands';
import { useWorkflowHostCommands } from '@features/workflow/ui/WorkflowUiContext';
-import { getFormChildren, getResolvedWorkflowEdges, getWorkflowFieldInvalidReason } from '@features/workflow/utility';
+import {
+ getFormChildren,
+ getResolvedWorkflowEdges,
+ getWorkflowFieldInvalidReason,
+ isShuffleableField,
+} from '@features/workflow/utility';
import { Button, DropZone, IconButton } from '@platform/ui';
import { MenuContent } from '@platform/ui/Menu';
-import { Columns2Icon, CrosshairIcon, GripVerticalIcon, InfoIcon, PlusIcon, Rows2Icon, XIcon } from 'lucide-react';
+import {
+ Columns2Icon,
+ CrosshairIcon,
+ DicesIcon,
+ GripVerticalIcon,
+ InfoIcon,
+ PlusIcon,
+ Rows2Icon,
+ XIcon,
+} from 'lucide-react';
import {
createContext,
memo,
@@ -301,6 +316,38 @@ const ContainerDropZoneBase = ({ container, isEmpty }: { container: ContainerFor
const ContainerDropZone = memo(ContainerDropZoneBase);
/** The shared description popover, bound through the form element. */
+/** Seed fields own a dice already; other numeric fields opt into one per form element. */
+const ShuffleToggleAction = ({
+ element,
+ projectGraph,
+}: {
+ element: NodeFieldFormElement;
+ projectGraph: ProjectGraphState;
+}) => {
+ const { editGraph } = useProjectGraphCommands();
+ const { template } = useNodeFieldBinding(element, projectGraph);
+
+ if (!template || !isShuffleableField(template) || isSeedInputField(template)) {
+ return null;
+ }
+
+ const { showShuffle } = element.data;
+
+ return (
+ <IconButton
+ aria-label="Show shuffle button"
+ aria-pressed={showShuffle}
+ color={showShuffle ? 'accent.solid' : undefined}
+ size="2xs"
+ title={showShuffle ? 'Hide shuffle button' : 'Show shuffle button'}
+ variant="ghost"
+ onClick={() => editGraph({ elementId: element.id, showShuffle: !showShuffle, type: 'setNodeFieldShowShuffle' })}
+ >
+ <Icon as={DicesIcon} boxSize="3" />
+ </IconButton>
+ );
+};
+
const FieldDescriptionAction = ({
element,
projectGraph,
@@ -397,8 +444,10 @@ const BuilderElementBase = ({
<Icon as={CrosshairIcon} boxSize="3" />
</IconButton>
<FieldDescriptionAction element={element} projectGraph={projectGraph} />
+ <ShuffleToggleAction element={element} projectGraph={projectGraph} />
<IconButton
- aria-label="Toggle description"
+ aria-label="Show field description"
+ aria-pressed={element.data.showDescription}
color={element.data.showDescription ? 'accent.solid' : undefined}
size="2xs"
title={element.data.showDescription ? 'Hide field description' : 'Show field description'}
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 e3d2b89490..3ace30d684 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/linear/NodeFieldControl.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/NodeFieldControl.tsx
@@ -1,20 +1,22 @@
import type { SeedMode } from '@platform/core/seed';
-import { Alert, Field, HStack, Icon, Input, Stack, Text } from '@chakra-ui/react';
+import { Alert, Box, Field, HStack, Icon, Input, Stack, Text } from '@chakra-ui/react';
import { isInvocationNode, type NodeFieldFormElement, type ProjectGraphState } from '@features/workflow/contracts';
-import { getWorkflowFieldSeedMode } from '@features/workflow/graph';
+import { getWorkflowFieldSeedMode, isSeedInputField } from '@features/workflow/graph';
import { useInvocationTemplatesSelector } from '@features/workflow/react';
import { WorkflowFieldInput } from '@features/workflow/ui/fields/WorkflowFieldInput';
import { useProjectGraphCommands } from '@features/workflow/ui/useProjectGraphCommands';
import {
cloneWorkflowFieldDefault,
+ getRandomWorkflowFieldValue,
getResolvedWorkflowEdges,
getWorkflowFieldInvalidReason,
isDirectInputField,
+ isShuffleableField,
isWorkflowFieldValueDefault,
} from '@features/workflow/utility';
import { FieldLabel, IconButton, Tooltip } from '@platform/ui';
-import { RotateCcwIcon } from 'lucide-react';
+import { DicesIcon, RotateCcwIcon } from 'lucide-react';
import { useCallback, useMemo, useState, type ChangeEvent } from 'react';
import { useTranslation } from 'react-i18next';
@@ -103,6 +105,17 @@ export const NodeFieldControl = ({
[editGraph, fieldName, nodeId]
);
const resetAriaLabel = useMemo(() => `Reset ${label} to default value`, [label]);
+ const showsShuffle =
+ element.data.showShuffle &&
+ !!template &&
+ !isConnected &&
+ isShuffleableField(template) &&
+ !isSeedInputField(template);
+ const onShuffleClick = useCallback(() => {
+ if (template) {
+ editGraph({ fieldName, nodeId, type: 'setFieldValue', value: getRandomWorkflowFieldValue(template) });
+ }
+ }, [editGraph, fieldName, nodeId, template]);
if (!invocationNode || !template) {
return (
@@ -171,16 +184,34 @@ export const NodeFieldControl = ({
{t('nodes.providedByConnection')}
</Text>
) : (
- <WorkflowFieldInput
- id={valueInputId}
- invalid={isInvalid}
- nodeId={nodeId}
- seedMode={getWorkflowFieldSeedMode(instance)}
- template={template}
- value={instance?.value}
- onChange={onValueChange}
- onSeedModeChange={onSeedModeChange}
- />
+ <HStack alignItems="start" gap="1" minW="0" w="full">
+ <Box flex="1" minW="0">
+ <WorkflowFieldInput
+ id={valueInputId}
+ invalid={isInvalid}
+ nodeId={nodeId}
+ seedMode={getWorkflowFieldSeedMode(instance)}
+ template={template}
+ value={instance?.value}
+ onChange={onValueChange}
+ onSeedModeChange={onSeedModeChange}
+ />
+ </Box>
+ {showsShuffle ? (
+ <Tooltip content={t('common.shuffle')}>
+ <IconButton
+ aria-label={`${t('common.shuffle')} ${label}`}
+ color="fg.muted"
+ flexShrink={0}
+ size="xs"
+ variant="outline"
+ onClick={onShuffleClick}
+ >
+ <Icon as={DicesIcon} boxSize="3.5" />
+ </IconButton>
+ </Tooltip>
+ ) : null}
+ </HStack>
)}
{invalidReason ? <Field.ErrorText fontSize="2xs">{invalidReason}</Field.ErrorText> : null}
</Stack>
diff --git a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
index cc5af4777b..0ddeaaa626 100644
--- a/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
+++ b/invokeai/frontend/webv2/src/workbench/autoRoutePolicy.ts
@@ -98,6 +98,7 @@ const GRAPH_EDIT_CONFIDENCE = {
setFormElementContent: false,
setMetadata: false,
setNodeFieldShowDescription: false,
+ setNodeFieldShowShuffle: false,
setNodeIsIntermediate: false,
setNodeIsOpen: false,
setNodeLabel: false,