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): toggle negative prompt, remember textarea height
joshistoaste133a89353f3
diff --git a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsxindex 5e40bfc277..cc42ab1274 100644--- a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx+++ b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx@@ -141,7 +141,7 @@ const submitQueueItem = (batchCount: generateValues.batchCount,destination: queueItem.snapshot.destination,graph,- negativePrompt: generateValues.negativePrompt,+ negativePrompt: generateValues.negativePromptEnabled ? generateValues.negativePrompt : '',negativePromptNodeId: 'negative_prompt',positivePrompt: generateValues.positivePrompt,positivePromptNodeId: 'positive_prompt',diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/Field.tsx b/invokeai/frontend/webv2/src/workbench/components/ui/Field.tsxindex 21a1479536..153073fa9c 100644--- a/invokeai/frontend/webv2/src/workbench/components/ui/Field.tsx+++ b/invokeai/frontend/webv2/src/workbench/components/ui/Field.tsx@@ -1,6 +1,6 @@import type { ReactNode } from 'react';-import { Stack, Text, useRecipe, type StackProps } from '@chakra-ui/react';+import { HStack, Stack, Text, useRecipe, type StackProps } from '@chakra-ui/react';import { fieldLabelRecipe } from '@theme/recipes';/**@@ -20,6 +20,7 @@ export const FieldLabel = ({ children }: { children: ReactNode }) => {export interface FieldProps extends Omit<StackProps, 'title'> {label: string;+ labelEnd?: ReactNode;/** Validation error, shown in place of `helpText`. Mark the control itself invalid via `aria-invalid`. */error?: string | null;helpText?: string;@@ -27,9 +28,12 @@ export interface FieldProps extends Omit<StackProps, 'title'> {}/** A labelled form field: an uppercase label stacked above its control, with an optional help/error line below. */-export const Field = ({ children, error, helpText, label, ...rest }: FieldProps) => (+export const Field = ({ children, error, helpText, label, labelEnd, ...rest }: FieldProps) => (<Stack flex="1" gap="1.5" minW="0" {...rest}>- <FieldLabel>{label}</FieldLabel>+ <HStack align="center" justify="space-between" minW="0">+ <FieldLabel>{label}</FieldLabel>+ {labelEnd}+ </HStack>{children}{error ? (<Text color="fg.error" fontSize="2xs" role="alert">diff --git a/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.test.ts b/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.test.tsindex 567ab4cb66..2bdf585925 100644--- a/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.test.ts+++ b/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.test.ts@@ -140,29 +140,36 @@ describe('BASE_GENERATION', () => {});it('matches expected prompt policy per base', () => {- expect(getPromptPolicy(createModel('flux'), { cfgScale: 4 })).toMatchObject({+ expect(getPromptPolicy(createModel('flux'), { cfgScale: 4, negativePromptEnabled: true })).toMatchObject({negativeVisible: false,negativeUsedInGraph: false,});- expect(getPromptPolicy(createModel('sdxl'), { cfgScale: 1 })).toMatchObject({+ expect(getPromptPolicy(createModel('sdxl'), { cfgScale: 1, negativePromptEnabled: true })).toMatchObject({negativeVisible: true,negativeUsedInGraph: true,});- expect(getPromptPolicy(createModel('qwen-image'), { cfgScale: 1 })).toMatchObject({+ expect(getPromptPolicy(createModel('sdxl'), { cfgScale: 1, negativePromptEnabled: false })).toMatchObject({negativeVisible: true,negativeUsedInGraph: false,});- expect(getPromptPolicy(createModel('qwen-image'), { cfgScale: 2 })).toMatchObject({+ expect(getPromptPolicy(createModel('qwen-image'), { cfgScale: 1, negativePromptEnabled: true })).toMatchObject({+ negativeVisible: true,+ negativeUsedInGraph: false,+ });+ expect(getPromptPolicy(createModel('qwen-image'), { cfgScale: 2, negativePromptEnabled: true })).toMatchObject({negativeVisible: true,negativeUsedInGraph: true,negativeHelpText: 'Used only when CFG is greater than 1.',});- expect(getPromptPolicy(externalModel, { cfgScale: 7 })).toMatchObject({+ expect(getPromptPolicy(externalModel, { cfgScale: 7, negativePromptEnabled: true })).toMatchObject({negativeVisible: false,negativeUsedInGraph: false,});expect(- getPromptPolicy({ ...externalModel, capabilities: { supports_negative_prompt: true } }, { cfgScale: 7 })+ getPromptPolicy(+ { ...externalModel, capabilities: { supports_negative_prompt: true } },+ { cfgScale: 7, negativePromptEnabled: true }+ )).toMatchObject({ negativeVisible: true, negativeUsedInGraph: true });});diff --git a/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.tsindex e1952d8600..f37542f170 100644--- a/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.ts+++ b/invokeai/frontend/webv2/src/workbench/generation/baseGenerationPolicies.ts@@ -400,21 +400,23 @@ export const coerceSchedulerForGraph = (export const getPromptPolicy = (model: GenerateModelConfig | undefined,- settings: Pick<GenerateSettings, 'cfgScale'>+ settings: Pick<GenerateSettings, 'cfgScale' | 'negativePromptEnabled'>) => {if (model?.type === 'external_image_generator') {const supportsNegativePrompt = model.capabilities?.supports_negative_prompt === true;return {negativeVisible: supportsNegativePrompt,- negativeUsedInGraph: supportsNegativePrompt,+ negativeUsedInGraph: settings.negativePromptEnabled && supportsNegativePrompt,};}const config = getBaseGenerationConfig(model);// Visibility controls the textarea; usage controls whether the graph wires negative conditioning.const negativeUsedInGraph =- config.negativePrompt.usage === 'always' || (config.negativePrompt.usage === 'cfg-gated' && settings.cfgScale > 1);+ settings.negativePromptEnabled &&+ (config.negativePrompt.usage === 'always' ||+ (config.negativePrompt.usage === 'cfg-gated' && settings.cfgScale > 1));return {negativeVisible: config.negativePrompt.visible,@@ -509,8 +511,11 @@ export const getDefaultGenerateSettings = (model?: GenerateModelConfig): Generatheight,loras: [],modelKey: model?.key ?? '',+ negativePromptEnabled: true,negativePrompt: '',+ negativePromptHeightPx: 56,positivePrompt: '',+ positivePromptHeightPx: 96,qwen3EncoderModel: null,qwenVLEncoderModel: null,scheduler: defaults.scheduler,diff --git a/invokeai/frontend/webv2/src/workbench/generation/settings.test.ts b/invokeai/frontend/webv2/src/workbench/generation/settings.test.tsindex 288824e12f..2d46a7939d 100644--- a/invokeai/frontend/webv2/src/workbench/generation/settings.test.ts+++ b/invokeai/frontend/webv2/src/workbench/generation/settings.test.ts@@ -54,6 +54,9 @@ describe('normalizeGenerateSettings', () => {expect(normalized?.clipSkip).toBe(0);expect(normalized?.colorCompensation).toBe(false);expect(normalized?.loras).toEqual([]);+ expect(normalized?.negativePromptEnabled).toBe(true);+ expect(normalized?.negativePromptHeightPx).toBe(56);+ expect(normalized?.positivePromptHeightPx).toBe(96);expect(normalized?.seamlessXAxis).toBe(false);expect(normalized?.vae).toBeNull();expect(normalized?.vaePrecision).toBe('fp32');diff --git a/invokeai/frontend/webv2/src/workbench/generation/settings.ts b/invokeai/frontend/webv2/src/workbench/generation/settings.tsindex cfa6e91bfd..087025be8d 100644--- a/invokeai/frontend/webv2/src/workbench/generation/settings.ts+++ b/invokeai/frontend/webv2/src/workbench/generation/settings.ts@@ -53,6 +53,12 @@ export const MIN_DIMENSION = 64;export const MAX_DIMENSION = 4096;export const SEED_MAX = 4_294_967_295;+export const MIN_NEGATIVE_PROMPT_HEIGHT_PX = 56;+export const MAX_NEGATIVE_PROMPT_HEIGHT_PX = 240;+export const DEFAULT_NEGATIVE_PROMPT_HEIGHT_PX = 56;+export const MIN_POSITIVE_PROMPT_HEIGHT_PX = 96;+export const MAX_POSITIVE_PROMPT_HEIGHT_PX = 360;+export const DEFAULT_POSITIVE_PROMPT_HEIGHT_PX = 96;export const DEFAULT_LORA_WEIGHT_CONFIG = {coarseStep: 0.05,@@ -99,6 +105,9 @@ const isRecord = (value: unknown): value is Record<string, unknown> => Boolean(vconst hasFiniteNumber = (record: Record<string, unknown>, key: string): boolean =>typeof record[key] === 'number' && Number.isFinite(record[key]);+const getClampedNumber = (record: Record<string, unknown>, key: string, min: number, max: number, fallback: number) =>+ hasFiniteNumber(record, key) ? Math.min(Math.max(record[key] as number, min), max) : fallback;+export const isMainModelConfig = (value: unknown): value is MainModelConfig =>isRecord(value) &&typeof value.key === 'string' &&@@ -354,8 +363,23 @@ export const normalizeGenerateSettings = (values: unknown): GenerateSettings | nheight,loras: Array.isArray(values.loras) ? values.loras.filter(isGenerateLora) : [],modelKey: values.modelKey as string,+ negativePromptEnabled: typeof values.negativePromptEnabled === 'boolean' ? values.negativePromptEnabled : true,negativePrompt: values.negativePrompt as string,+ negativePromptHeightPx: getClampedNumber(+ values,+ 'negativePromptHeightPx',+ MIN_NEGATIVE_PROMPT_HEIGHT_PX,+ MAX_NEGATIVE_PROMPT_HEIGHT_PX,+ DEFAULT_NEGATIVE_PROMPT_HEIGHT_PX+ ),positivePrompt: values.positivePrompt as string,+ positivePromptHeightPx: getClampedNumber(+ values,+ 'positivePromptHeightPx',+ MIN_POSITIVE_PROMPT_HEIGHT_PX,+ MAX_POSITIVE_PROMPT_HEIGHT_PX,+ DEFAULT_POSITIVE_PROMPT_HEIGHT_PX+ ),scheduler: values.scheduler as string,seamlessXAxis: typeof values.seamlessXAxis === 'boolean' ? values.seamlessXAxis : false,seamlessYAxis: typeof values.seamlessYAxis === 'boolean' ? values.seamlessYAxis : false,@@ -399,6 +423,9 @@ export const isGenerateSettings = (values: unknown): values is GenerateSettingshasFiniteNumber(values, 'aspectRatioValue') &&hasFiniteNumber(values, 'clipSkip') &&typeof values.colorCompensation === 'boolean' &&+ typeof values.negativePromptEnabled === 'boolean' &&+ hasFiniteNumber(values, 'negativePromptHeightPx') &&+ hasFiniteNumber(values, 'positivePromptHeightPx') &&Array.isArray(values.loras) &&values.loras.every(isGenerateLora) &&typeof values.seamlessXAxis === 'boolean' &&diff --git a/invokeai/frontend/webv2/src/workbench/generation/types.ts b/invokeai/frontend/webv2/src/workbench/generation/types.tsindex e81e3edcd9..be99df69f7 100644--- a/invokeai/frontend/webv2/src/workbench/generation/types.ts+++ b/invokeai/frontend/webv2/src/workbench/generation/types.ts@@ -91,7 +91,10 @@ export interface GenerateSettings {batchCount: number;modelKey: string;positivePrompt: string;+ positivePromptHeightPx: number;+ negativePromptEnabled: boolean;negativePrompt: string;+ negativePromptHeightPx: number;width: number;height: number;aspectRatioId: AspectRatioId;diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.tsindex 4b54c23083..dd64eb7857 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts@@ -46,8 +46,11 @@ const createValues = (overrides: Partial<GenerateWidgetValues> = {}): GenerateWiloras: [],model: sdxlModel,modelKey: sdxlModel.key,+ negativePromptEnabled: true,negativePrompt: '',+ negativePromptHeightPx: 56,positivePrompt: '',+ positivePromptHeightPx: 96,qwen3EncoderModel: null,qwenVLEncoderModel: null,scheduler: 'euler_a',diff --git a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/GeneratePromptFields.tsx b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/GeneratePromptFields.tsxindex 2496c12df0..af53a56b8d 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/GeneratePromptFields.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/GeneratePromptFields.tsx@@ -16,16 +16,22 @@ export const GeneratePromptFields = ({ onCommit, selectedModel, settings }: Geneconst promptPolicy = getPromptPolicy(selectedModel, settings);return (- <Stack gap="1" pt="2">+ <Stack gap="1" py="2"><PositivePromptField+ heightPx={settings.positivePromptHeightPx}value={settings.positivePrompt}onChange={(positivePrompt) => onCommit({ positivePrompt })}+ onResizeEnd={(positivePromptHeightPx) => onCommit({ positivePromptHeightPx })}/>{promptPolicy.negativeVisible ? (<NegativePromptField+ heightPx={settings.negativePromptHeightPx}+ isEnabled={settings.negativePromptEnabled}helpText={promptPolicy.negativeHelpText}value={settings.negativePrompt}+ onEnabledChange={(negativePromptEnabled) => onCommit({ negativePromptEnabled })}onChange={(negativePrompt) => onCommit({ negativePrompt })}+ onResizeEnd={(negativePromptHeightPx) => onCommit({ negativePromptHeightPx })}/>) : null}</Stack>diff --git a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsx b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsxindex f54b6c0c03..f6bb8a1809 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/NegativePromptField.tsx@@ -1,25 +1,53 @@import type { ChangeEvent } from 'react';+import { Switch } from '@chakra-ui/react';import { Field, ResizableTextarea } from '@workbench/components/ui';interface NegativePromptFieldProps {+ heightPx: number;helpText?: string;+ isEnabled: boolean;value: string;onChange: (value: string) => void;+ onEnabledChange: (isEnabled: boolean) => void;+ onResizeEnd: (heightPx: number) => void;}-export const NegativePromptField = ({ helpText, onChange, value }: NegativePromptFieldProps) => (- <Field label="Negative prompt" helpText={helpText}>- <ResizableTextarea- aria-label="Negative prompt"- defaultHeightPx={56}- maxHeightPx={240}- minHeightPx={56}- resizeHandleAriaLabel="Resize negative prompt"- size="xs"- fontFamily="mono"- value={value}- onChange={(event: ChangeEvent<HTMLTextAreaElement>) => onChange(event.currentTarget.value)}- />+export const NegativePromptField = ({+ heightPx,+ helpText,+ isEnabled,+ onChange,+ onEnabledChange,+ onResizeEnd,+ value,+}: NegativePromptFieldProps) => (+ <Field+ label="Negative prompt"+ labelEnd={+ <Switch.Root checked={isEnabled} size="sm" onCheckedChange={(event) => onEnabledChange(event.checked)}>+ <Switch.HiddenInput />+ <Switch.Control _checked={{ bg: 'accent.solid' }}>+ <Switch.Thumb />+ </Switch.Control>+ <Switch.Label srOnly>Enable negative prompt</Switch.Label>+ </Switch.Root>+ }+ helpText={isEnabled ? helpText : undefined}+ >+ {isEnabled ? (+ <ResizableTextarea+ aria-label="Negative prompt"+ defaultHeightPx={heightPx}+ maxHeightPx={240}+ minHeightPx={56}+ resizeHandleAriaLabel="Resize negative prompt"+ size="xs"+ fontFamily="mono"+ value={value}+ onChange={(event: ChangeEvent<HTMLTextAreaElement>) => onChange(event.currentTarget.value)}+ onResizeEnd={onResizeEnd}+ />+ ) : null}</Field>);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsx b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsxindex 5bbf99a02f..01994c7472 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/generate/promptFields/PositivePromptField.tsx@@ -5,15 +5,17 @@ import { Field, ResizableTextarea } from '@workbench/components/ui';import { registerPositivePromptElement } from './promptFocus';interface PositivePromptFieldProps {+ heightPx: number;value: string;onChange: (value: string) => void;+ onResizeEnd: (heightPx: number) => void;}-export const PositivePromptField = ({ onChange, value }: PositivePromptFieldProps) => (+export const PositivePromptField = ({ heightPx, onChange, onResizeEnd, value }: PositivePromptFieldProps) => (<Field label="Prompt"><ResizableTextareaaria-label="Positive prompt"- defaultHeightPx={96}+ defaultHeightPx={heightPx}maxHeightPx={360}minHeightPx={96}resizeHandleAriaLabel="Resize positive prompt"@@ -22,6 +24,7 @@ export const PositivePromptField = ({ onChange, value }: PositivePromptFieldProptextareaRef={registerPositivePromptElement}value={value}onChange={(event: ChangeEvent<HTMLTextAreaElement>) => onChange(event.currentTarget.value)}+ onResizeEnd={onResizeEnd}/></Field>);diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.tsindex be3e0cf8f1..2458a5eb8b 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts@@ -31,8 +31,11 @@ const createGenerateValues = (overrides: Partial<GenerateWidgetValues> = {}): Geloras: [],model,modelKey: model.key,+ negativePromptEnabled: true,negativePrompt: '',+ negativePromptHeightPx: 56,positivePrompt: 'first prompt',+ positivePromptHeightPx: 96,qwen3EncoderModel: null,qwenVLEncoderModel: null,scheduler: 'euler_a',