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): promote conditioning rebalance to the model section
joshistoast8ab3e5650f36
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 862f6aaec6..d59853abd6 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -557,6 +557,14 @@"heading": "LoRA","paragraphs": ["Lightweight models that are used in conjunction with base models."]},+ "conditioningRebalance": {+ "heading": "Conditioning rebalance",+ "paragraphs": [+ "Krea 2 reads your prompt through twelve tapped layers of its text encoder and stacks them together. Each bar sets how much one of those layers counts.",+ "Shallow taps, on the left, track the prompt's literal wording. Deep taps, on the right, track its meaning and composition. Raising the deep taps pushes the model harder toward what you asked for; raising the shallow taps holds it closer to how you phrased it.",+ "Gain scales the whole stack afterwards, which counteracts the quality dilution from distillation. Leave both at the defaults unless prompt adherence is the problem you are solving."+ ]+ },"creativity": {"heading": "Creativity","paragraphs": [@@ -1297,11 +1305,26 @@"incompatibleSettingsClearedDescription_other": "{{labels}} were not compatible with {{name}}.","installTextLlmToExpandPrompts": "Install a Text LLM model to expand prompts.","installVisionModelToGeneratePrompts": "Install a LLaVA OneVision model to generate prompts from images.",- "krea2Rebalance": "Rebalance",+ "krea2Rebalance": "Conditioning rebalance",+ "krea2RebalanceAxisDeep": "deep",+ "krea2RebalanceAxisShallow": "shallow",+ "krea2RebalanceGain": "Gain",+ "krea2RebalanceGainReset": "Reset gain","krea2RebalanceHelp": "Scales conditioning toward the prompt before denoising.",- "krea2RebalanceMultiplier": "Rebalance multiplier",- "krea2RebalanceWeights": "Per-layer weights",- "krea2RebalanceWeightsHelp": "{{count}} comma-separated numbers, one per layer.",+ "krea2RebalancePreset": "Rebalance preset",+ "krea2RebalancePresetActions": "Preset actions",+ "krea2RebalancePresetCustom": "Custom",+ "krea2RebalancePresetDelete": "Delete preset",+ "krea2RebalancePresetDeleteBody": "Delete the saved preset \"{{name}}\"? This cannot be undone.",+ "krea2RebalancePresetName": "Preset name",+ "krea2RebalancePresetRename": "Rename preset",+ "krea2RebalancePresetSave": "Save current as preset",+ "krea2RebalancePresetSaveAction": "Save",+ "krea2RebalanceReset": "Reset to default curve",+ "krea2RebalanceTapLabel": "Tap {{tap}}, encoder layer {{layer}}",+ "krea2RebalanceTapReadout": "tap {{tap}} · {{value}}",+ "krea2RebalanceWeights": "Per-tap weights",+ "krea2RebalanceWeightsHelp": "{{count}} comma-separated numbers, one per tap.","krea2RebalanceWeightsInvalid": "Enter exactly {{count}} comma-separated numbers.","krea2SeedVariance": "Seed variance","krea2SeedVarianceHelp": "Perturbs conditioning so nearby seeds diverge more.",diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConditioningRebalanceField.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConditioningRebalanceField.browser.test.tsxnew file mode 100644index 0000000000..73e137d0ed--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConditioningRebalanceField.browser.test.tsx@@ -0,0 +1,290 @@+/* oxlint-disable react-perf/jsx-no-new-function-as-prop */+import type { RebalancePreset } from '@features/generation/core/conditioningRebalance';+import type { GenerateSettings } from '@features/generation/core/types';++import { ChakraProvider } from '@chakra-ui/react';+import {+ DEFAULT_KREA2_REBALANCE_MULTIPLIER,+ DEFAULT_KREA2_REBALANCE_WEIGHTS,+ NEUTRAL_KREA2_REBALANCE_WEIGHTS,+} from '@features/generation/core/conditioningRebalance';+import { system } from '@theme/system';+import i18next from 'i18next';+import { act, useState } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { initReactI18next, I18nextProvider } from 'react-i18next';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { GenerateConditioningRebalanceField } from './GenerateConditioningRebalanceField';+import { GenerationUiProvider, type GenerationUiAdapter } from './GenerationUiContext';++const i18n = i18next.createInstance();+await i18n.use(initReactI18next).init({+ fallbackLng: 'en',+ lng: 'en',+ resources: {+ en: {+ translation: {+ widgets: {+ generate: {+ krea2Rebalance: 'Conditioning rebalance',+ krea2RebalanceAxisDeep: 'deep',+ krea2RebalanceAxisShallow: 'shallow',+ krea2RebalanceGain: 'Gain',+ krea2RebalanceGainReset: 'Reset gain',+ krea2RebalanceHelp: 'Scales conditioning toward the prompt before denoising.',+ krea2RebalancePreset: 'Rebalance preset',+ krea2RebalancePresetActions: 'Preset actions',+ krea2RebalancePresetCustom: 'Custom',+ krea2RebalancePresetDelete: 'Delete preset',+ krea2RebalancePresetDeleteBody: 'Delete "{{name}}"?',+ krea2RebalancePresetName: 'Preset name',+ krea2RebalancePresetRename: 'Rename preset',+ krea2RebalancePresetSave: 'Save current as preset',+ krea2RebalancePresetSaveAction: 'Save',+ krea2RebalanceReset: 'Reset to default curve',+ krea2RebalanceTapLabel: 'Tap {{tap}}, encoder layer {{layer}}',+ krea2RebalanceTapReadout: 'tap {{tap}} · {{value}}',+ krea2RebalanceWeights: 'Per-tap weights',+ krea2RebalanceWeightsInvalid: 'Enter exactly {{count}} comma-separated numbers.',+ },+ },+ },+ },+ },+});++let host: HTMLDivElement | null = null;+let root: Root | null = null;+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++const onCommit = vi.fn();+const onCommitImmediate = vi.fn();+const savePreset = vi.fn();+const renamePreset = vi.fn();+const removePreset = vi.fn();++let customPresets: RebalancePreset[] = [];++/**+ * The field reads exactly one sub-port and three settings keys. Building the whole+ * adapter would only couple this test to parts of the port it never touches.+ */+const buildAdapter = (): GenerationUiAdapter =>+ ({+ rebalancePresets: {+ presets: customPresets,+ remove: removePreset,+ rename: renamePreset,+ save: savePreset,+ },+ }) as unknown as GenerationUiAdapter;++const buildSettings = (overrides: Partial<GenerateSettings> = {}): GenerateSettings =>+ ({+ krea2RebalanceEnabled: true,+ krea2RebalanceMultiplier: DEFAULT_KREA2_REBALANCE_MULTIPLIER,+ krea2RebalanceWeights: DEFAULT_KREA2_REBALANCE_WEIGHTS,+ ...overrides,+ }) as unknown as GenerateSettings;++/** Mirrors the real form: commits land back on the rendered settings. */+const Harness = ({ initial }: { initial: Partial<GenerateSettings> }) => {+ const [settings, setSettings] = useState(() => buildSettings(initial));+ const apply = (patch: Partial<GenerateSettings>) => setSettings((current) => ({ ...current, ...patch }));++ return (+ <GenerateConditioningRebalanceField+ settings={settings}+ onCommit={(patch) => {+ onCommit(patch);+ apply(patch);+ }}+ onCommitImmediate={(patch) => {+ onCommitImmediate(patch);+ apply(patch);+ }}+ />+ );+};++const renderField = async (initial: Partial<GenerateSettings> = {}) => {+ await act(() =>+ root?.render(+ <I18nextProvider i18n={i18n}>+ <ChakraProvider value={system}>+ <GenerationUiProvider adapter={buildAdapter()}>+ <Harness initial={initial} />+ </GenerationUiProvider>+ </ChakraProvider>+ </I18nextProvider>+ )+ );+};++const interact = async (run: () => void) => {+ await act(async () => {+ run();+ await new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 40);+ });+ });+};++/** Scoped by orientation: the Gain slider's thumb is a `role="slider"` too. */+const bars = () => [...document.querySelectorAll('[role="slider"][aria-orientation="vertical"]')];++const byLabel = (label: string): HTMLElement | null =>+ document.querySelector(`[aria-label="${label}"]`) as HTMLElement | null;++const weightsInput = (): HTMLInputElement => {+ const input = byLabel('Per-tap weights');++ if (!(input instanceof HTMLInputElement)) {+ throw new Error('weights input did not render');+ }++ return input;+};++/** React tracks its own value on the node, so a plain assignment is ignored. */+const typeInto = (input: HTMLInputElement, value: string) => {+ const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;++ setter?.call(input, value);+ input.dispatchEvent(new Event('input', { bubbles: true }));+};++beforeEach(() => {+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);+ customPresets = [];+ onCommit.mockClear();+ onCommitImmediate.mockClear();+ savePreset.mockClear();+ renamePreset.mockClear();+ removePreset.mockClear();+});++afterEach(async () => {+ await act(() => root?.unmount());+ document+ .querySelectorAll('[data-scope="select"][data-part="positioner"], [data-scope="menu"][data-part="positioner"]')+ .forEach((element) => element.remove());+ host?.remove();+ host = null;+ root = null;+});++describe('GenerateConditioningRebalanceField', () => {+ it('shows only the switch and a preview while disabled', async () => {+ await renderField({ krea2RebalanceEnabled: false });++ expect(document.body.textContent).toContain('Conditioning rebalance');+ expect(bars()).toHaveLength(0);+ expect(byLabel('Per-tap weights')).toBeNull();+ // The collapsed row still previews the curve.+ expect(document.querySelector('svg[aria-hidden]')).not.toBeNull();+ });++ it('turns the editor on from the collapsed row', async () => {+ await renderField({ krea2RebalanceEnabled: false });++ const toggle = byLabel('Conditioning rebalance');++ await interact(() => toggle?.click());++ expect(onCommitImmediate).toHaveBeenCalledWith({ krea2RebalanceEnabled: true });+ expect(bars()).toHaveLength(12);+ });++ it('labels the axis by encoder depth rather than a frequency metaphor', async () => {+ await renderField();++ expect(document.body.textContent).toContain('shallow');+ expect(document.body.textContent).toContain('deep');+ expect(bars()[0]?.getAttribute('aria-label')).toBe('Tap 1, encoder layer 2');+ });++ it('disables reset at the backend defaults and restores them once edited', async () => {+ await renderField();++ const reset = byLabel('Reset to default curve');++ expect(reset?.getAttribute('disabled')).not.toBeNull();++ await interact(() => typeInto(weightsInput(), NEUTRAL_KREA2_REBALANCE_WEIGHTS));++ expect(byLabel('Reset to default curve')?.getAttribute('disabled')).toBeNull();++ await interact(() => byLabel('Reset to default curve')?.click());++ expect(onCommitImmediate).toHaveBeenLastCalledWith({+ krea2RebalanceMultiplier: DEFAULT_KREA2_REBALANCE_MULTIPLIER,+ krea2RebalanceWeights: DEFAULT_KREA2_REBALANCE_WEIGHTS,+ });+ expect(weightsInput().value).toBe(DEFAULT_KREA2_REBALANCE_WEIGHTS);+ });++ it('commits a typed vector the backend would accept', async () => {+ await renderField();++ await interact(() => typeInto(weightsInput(), NEUTRAL_KREA2_REBALANCE_WEIGHTS));++ expect(onCommitImmediate).toHaveBeenLastCalledWith({ krea2RebalanceWeights: NEUTRAL_KREA2_REBALANCE_WEIGHTS });+ expect(bars()[0]?.getAttribute('aria-valuenow')).toBe('1');+ });++ it('reports an invalid vector without clobbering the bars', async () => {+ await renderField();++ await interact(() => typeInto(weightsInput(), '1,2,three'));++ expect(document.body.textContent).toContain('Enter exactly 12 comma-separated numbers.');+ // The last valid vector still drives the editor.+ expect(bars()[8]?.getAttribute('aria-valuenow')).toBe('5');+ expect(onCommitImmediate).not.toHaveBeenCalled();+ });++ it('holds a half-typed vector instead of normalizing it under the cursor', async () => {+ await renderField();++ await interact(() => typeInto(weightsInput(), '1.0,1.0,'));++ expect(weightsInput().value).toBe('1.0,1.0,');+ });++ it('falls back to Custom once the values leave every preset', async () => {+ await renderField();++ expect(document.body.textContent).toContain('Default');++ await interact(() => typeInto(weightsInput(), '1,1,1,1,1,1,1,2.5,5,1.1,4,7'));++ expect(document.body.textContent).toContain('Custom');+ });++ it('saves the current curve as a named preset', async () => {+ await renderField();++ await interact(() => byLabel('Preset actions')?.click());++ const saveItem = [...document.querySelectorAll('[role="menuitem"]')].find((item) =>+ item.textContent?.includes('Save current as preset')+ );++ await interact(() => (saveItem as HTMLElement | undefined)?.click());++ const nameInput = document.querySelector('[role="dialog"] input');++ if (!(nameInput instanceof HTMLInputElement)) {+ throw new Error('preset name dialog did not open');+ }++ await interact(() => typeInto(nameInput, 'Punchy'));+ await interact(() => nameInput.form?.requestSubmit());++ expect(savePreset).toHaveBeenCalledWith('Punchy', DEFAULT_KREA2_REBALANCE_WEIGHTS, 4);+ });+});diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConditioningRebalanceField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConditioningRebalanceField.tsxnew file mode 100644index 0000000000..b3d67b5d92--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConditioningRebalanceField.tsx@@ -0,0 +1,378 @@+/* oxlint-disable react-perf/jsx-no-new-object-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-jsx-as-prop */+import type { RebalancePreset } from '@features/generation/core/conditioningRebalance';+import type { GenerateSettings } from '@features/generation/core/types';++import { createListCollection, HStack, Icon, Input, Menu, Portal, Stack, Switch, Text } from '@chakra-ui/react';+import {+ BUILTIN_REBALANCE_PRESETS,+ DEFAULT_KREA2_REBALANCE_MULTIPLIER,+ DEFAULT_KREA2_REBALANCE_WEIGHTS,+ KREA2_REBALANCE_WEIGHT_COUNT,+ matchRebalancePreset,+ parseRebalanceWeights,+ REBALANCE_PRESET_DEFAULT_ID,+ serializeRebalanceWeights,+} from '@features/generation/core/conditioningRebalance';+// Imported by subpath rather than from the `@platform/ui` barrel: the barrel is at its+// direct-importer budget, so each call site here would otherwise cost against it.+import { IconButton } from '@platform/ui/Button';+import { ConfirmDialog } from '@platform/ui/ConfirmDialog';+import { Field } from '@platform/ui/Field';+import { MenuContent } from '@platform/ui/Menu';+import { RenameDialog } from '@platform/ui/RenameDialog';+import { Select } from '@platform/ui/Select';+import { Tooltip } from '@platform/ui/Tooltip';+import { MoreHorizontalIcon, RotateCcwIcon } from 'lucide-react';+import { useCallback, useId, useMemo, useState } from 'react';+import { useTranslation } from 'react-i18next';++import { useGenerationUi } from './GenerationUiContext';+import { ConditioningRebalanceBars } from './shared/ConditioningRebalanceBars';+import { ConditioningRebalanceSparkline } from './shared/ConditioningRebalanceSparkline';+import { SliderNumberField } from './shared/SliderNumberField';++/** The gain slider's practical range. Typed values may go to the legacy schema's bound. */+const GAIN_SLIDER_MAX = 10;+const GAIN_INPUT_MAX = 20;++const SELECT_CONTENT_PROPS = { maxH: '16rem' } as const;+const READOUT_PROPS = {+ color: 'fg.subtle',+ fontFamily: 'mono',+ fontSize: '2xs',+ // Reserved so the header does not reflow as the readout appears and clears.+ minH: '4',+ whiteSpace: 'nowrap',+} as const;++const DEFAULT_WEIGHT_VECTOR: readonly number[] = parseRebalanceWeights(DEFAULT_KREA2_REBALANCE_WEIGHTS) ?? [];++type PresetDialog = { mode: 'save' } | { mode: 'rename'; preset: RebalancePreset };++interface GenerateConditioningRebalanceFieldProps {+ settings: GenerateSettings;+ /** Debounced; used for the continuous controls. */+ onCommit: (patch: Partial<GenerateSettings>) => void;+ /** Immediate; used for discrete edits that should not sit in the draft. */+ onCommitImmediate: (patch: Partial<GenerateSettings>) => void;+}++/**+ * Krea-2's per-tap conditioning gains.+ *+ * The twelve bars weight the twelve Qwen3-VL encoder layers stacked into the+ * conditioning, shallow (the prompt's literal wording) to deep (its meaning and+ * composition); Gain scales the result. Collapsed, the row is a switch and a preview of+ * the current curve.+ */+export const GenerateConditioningRebalanceField = ({+ onCommit,+ onCommitImmediate,+ settings,+}: GenerateConditioningRebalanceFieldProps) => {+ const { t } = useTranslation();+ const { rebalancePresets } = useGenerationUi();+ // The switch shares the Field.Root with the controls below; an explicit id keeps its+ // label bound to its own hidden input rather than the Field's control id.+ const switchInputId = useId();++ const [previewWeights, setPreviewWeights] = useState<number[] | null>(null);+ const [activeIndex, setActiveIndex] = useState<number | null>(null);+ /** Non-null while the text field is being typed into, so a half-typed vector survives. */+ const [weightsDraft, setWeightsDraft] = useState<string | null>(null);+ const [presetDialog, setPresetDialog] = useState<PresetDialog | null>(null);+ const [presetPendingDelete, setPresetPendingDelete] = useState<RebalancePreset | null>(null);++ const committedWeights = useMemo(+ () => parseRebalanceWeights(settings.krea2RebalanceWeights) ?? DEFAULT_WEIGHT_VECTOR,+ [settings.krea2RebalanceWeights]+ );+ const weights = previewWeights ?? committedWeights;+ const isWeightsValid = parseRebalanceWeights(weightsDraft ?? settings.krea2RebalanceWeights) !== null;++ const presets = useMemo<RebalancePreset[]>(+ () => [...BUILTIN_REBALANCE_PRESETS, ...rebalancePresets.presets],+ [rebalancePresets.presets]+ );+ const presetCollection = useMemo(+ () =>+ createListCollection({+ itemToString: (preset: RebalancePreset) => preset.label,+ itemToValue: (preset: RebalancePreset) => preset.id,+ items: presets,+ }),+ [presets]+ );+ const activePresetId = matchRebalancePreset(+ presets,+ settings.krea2RebalanceWeights,+ settings.krea2RebalanceMultiplier+ );+ const activePreset = presets.find((preset) => preset.id === activePresetId) ?? null;+ const isCustomPreset =+ activePreset !== null && !BUILTIN_REBALANCE_PRESETS.some((preset) => preset.id === activePreset.id);+ const isAtDefault = activePresetId === REBALANCE_PRESET_DEFAULT_ID;++ const applyWeights = useCallback(+ (nextWeights: string, multiplier?: number) => {+ setWeightsDraft(null);+ setPreviewWeights(null);+ onCommitImmediate(+ multiplier === undefined+ ? { krea2RebalanceWeights: nextWeights }+ : { krea2RebalanceMultiplier: multiplier, krea2RebalanceWeights: nextWeights }+ );+ },+ [onCommitImmediate]+ );++ const handleBarsCommit = useCallback(+ (nextWeights: number[]) => {+ setWeightsDraft(null);+ setPreviewWeights(null);+ onCommit({ krea2RebalanceWeights: serializeRebalanceWeights(nextWeights) });+ },+ [onCommit]+ );++ const handleWeightsTextChange = useCallback(+ (value: string) => {+ setWeightsDraft(value);++ // Only a vector the backend would accept reaches the settings; the draft holds+ // everything in between so the field does not fight the cursor.+ if (parseRebalanceWeights(value) !== null) {+ onCommitImmediate({ krea2RebalanceWeights: value });+ }+ },+ [onCommitImmediate]+ );++ const handleReset = useCallback(() => {+ applyWeights(DEFAULT_KREA2_REBALANCE_WEIGHTS, DEFAULT_KREA2_REBALANCE_MULTIPLIER);+ }, [applyWeights]);++ const handlePresetChange = useCallback(+ (presetIds: string[]) => {+ const preset = presets.find((entry) => entry.id === presetIds[0]);++ if (preset) {+ applyWeights(preset.weights, preset.multiplier);+ }+ },+ [applyWeights, presets]+ );++ const handlePresetDialogSubmit = useCallback(+ (label: string) => {+ if (presetDialog?.mode === 'rename') {+ rebalancePresets.rename(presetDialog.preset.id, label);++ return;+ }++ rebalancePresets.save(label, settings.krea2RebalanceWeights, settings.krea2RebalanceMultiplier);+ },+ [presetDialog, rebalancePresets, settings.krea2RebalanceMultiplier, settings.krea2RebalanceWeights]+ );++ const handleConfirmDelete = useCallback(() => {+ if (presetPendingDelete) {+ rebalancePresets.remove(presetPendingDelete.id);+ }+ }, [presetPendingDelete, rebalancePresets]);++ const tapLabel = useCallback(+ (tap: number, layer: number) => t('widgets.generate.krea2RebalanceTapLabel', { layer, tap }),+ [t]+ );++ const activeWeight = activeIndex === null ? undefined : weights[activeIndex];+ const isEnabled = settings.krea2RebalanceEnabled;++ return (+ <>+ <Field+ borderColor="border.subtle"+ borderTopWidth="1px"+ helpText={isEnabled ? undefined : t('widgets.generate.krea2RebalanceHelp')}+ hint="conditioningRebalance"+ label={t('widgets.generate.krea2Rebalance')}+ labelEnd={+ <HStack gap="2">+ <ConditioningRebalanceSparkline muted={!isEnabled} weights={committedWeights} />+ <Switch.Root+ checked={isEnabled}+ ids={{ hiddenInput: switchInputId, label: `${switchInputId}-label` }}+ size="sm"+ onCheckedChange={({ checked }) => onCommitImmediate({ krea2RebalanceEnabled: checked })}+ >+ <Switch.HiddenInput aria-label={t('widgets.generate.krea2Rebalance')} />+ <Switch.Control _checked={{ bg: 'accent.solid' }}>+ <Switch.Thumb />+ </Switch.Control>+ </Switch.Root>+ </HStack>+ }+ pt="2"+ >+ {isEnabled ? (+ <Stack gap="2" w="full">+ <HStack gap="1">+ <Select+ aria-label={t('widgets.generate.krea2RebalancePreset')}+ collection={presetCollection}+ contentProps={SELECT_CONTENT_PROPS}+ flex="1"+ minW="0"+ size="xs"+ value={activePresetId === null ? [] : [activePresetId]}+ valueText={activePreset?.label ?? t('widgets.generate.krea2RebalancePresetCustom')}+ onValueChange={({ value }) => handlePresetChange(value)}+ />+ <Tooltip content={t('widgets.generate.krea2RebalanceReset')}>+ <IconButton+ aria-label={t('widgets.generate.krea2RebalanceReset')}+ color="fg.muted"+ disabled={isAtDefault}+ size="2xs"+ variant="ghost"+ onClick={handleReset}+ >+ <Icon as={RotateCcwIcon} boxSize="3" />+ </IconButton>+ </Tooltip>+ <Menu.Root lazyMount unmountOnExit>+ <Menu.Trigger asChild>+ <IconButton+ aria-label={t('widgets.generate.krea2RebalancePresetActions')}+ color="fg.muted"+ size="2xs"+ variant="ghost"+ >+ <Icon as={MoreHorizontalIcon} boxSize="3" />+ </IconButton>+ </Menu.Trigger>+ <Portal>+ <Menu.Positioner>+ <MenuContent minW="11rem">+ <Menu.Item+ disabled={!isWeightsValid}+ value="save"+ onClick={() => setPresetDialog({ mode: 'save' })}+ >+ <Menu.ItemText>{t('widgets.generate.krea2RebalancePresetSave')}</Menu.ItemText>+ </Menu.Item>+ <Menu.Item+ disabled={!isCustomPreset}+ value="rename"+ onClick={() => activePreset && setPresetDialog({ mode: 'rename', preset: activePreset })}+ >+ <Menu.ItemText>{t('widgets.generate.krea2RebalancePresetRename')}</Menu.ItemText>+ </Menu.Item>+ <Menu.Separator />+ <Menu.Item+ color="fg.error"+ disabled={!isCustomPreset}+ value="delete"+ onClick={() => activePreset && setPresetPendingDelete(activePreset)}+ >+ <Menu.ItemText>{t('widgets.generate.krea2RebalancePresetDelete')}</Menu.ItemText>+ </Menu.Item>+ </MenuContent>+ </Menu.Positioner>+ </Portal>+ </Menu.Root>+ </HStack>++ <Stack gap="1">+ <HStack justify="flex-end" {...READOUT_PROPS}>+ <Text as="span">+ {activeIndex !== null && activeWeight !== undefined+ ? t('widgets.generate.krea2RebalanceTapReadout', {+ tap: activeIndex + 1,+ value: activeWeight.toFixed(2),+ })+ : ''}+ </Text>+ </HStack>+ <ConditioningRebalanceBars+ activeIndex={activeIndex}+ tapLabel={tapLabel}+ weights={weights}+ onActiveIndexChange={setActiveIndex}+ onCommit={handleBarsCommit}+ onPreview={setPreviewWeights}+ />+ <HStack color="fg.subtle" fontSize="2xs" justify="space-between">+ <Text as="span">{t('widgets.generate.krea2RebalanceAxisShallow')}</Text>+ <Text as="span">{t('widgets.generate.krea2RebalanceAxisDeep')}</Text>+ </HStack>+ </Stack>++ <Field label={t('widgets.generate.krea2RebalanceGain')}>+ <SliderNumberField+ ariaLabel={t('widgets.generate.krea2RebalanceGain')}+ defaultValue={DEFAULT_KREA2_REBALANCE_MULTIPLIER}+ max={GAIN_SLIDER_MAX}+ min={0}+ numberInputMax={GAIN_INPUT_MAX}+ resetLabel={t('widgets.generate.krea2RebalanceGainReset')}+ step={0.1}+ value={settings.krea2RebalanceMultiplier}+ onChange={(multiplier) => onCommit({ krea2RebalanceMultiplier: multiplier })}+ />+ </Field>++ <Field+ error={+ isWeightsValid+ ? undefined+ : t('widgets.generate.krea2RebalanceWeightsInvalid', { count: KREA2_REBALANCE_WEIGHT_COUNT })+ }+ label={t('widgets.generate.krea2RebalanceWeights')}+ >+ <Input+ aria-label={t('widgets.generate.krea2RebalanceWeights')}+ fontFamily="mono"+ size="xs"+ value={+ weightsDraft ??+ (previewWeights ? serializeRebalanceWeights(previewWeights) : settings.krea2RebalanceWeights)+ }+ onBlur={() => setWeightsDraft(null)}+ onChange={(event) => handleWeightsTextChange(event.target.value)}+ />+ </Field>+ </Stack>+ ) : null}+ </Field>++ <RenameDialog+ initialName={presetDialog?.mode === 'rename' ? presetDialog.preset.label : ''}+ isOpen={presetDialog !== null}+ label={t('widgets.generate.krea2RebalancePresetName')}+ submitLabel={+ presetDialog?.mode === 'rename'+ ? t('widgets.generate.krea2RebalancePresetRename')+ : t('widgets.generate.krea2RebalancePresetSaveAction')+ }+ title={+ presetDialog?.mode === 'rename'+ ? t('widgets.generate.krea2RebalancePresetRename')+ : t('widgets.generate.krea2RebalancePresetSave')+ }+ onClose={() => setPresetDialog(null)}+ onSubmit={handlePresetDialogSubmit}+ />+ <ConfirmDialog+ body={t('widgets.generate.krea2RebalancePresetDeleteBody', { name: presetPendingDelete?.label ?? '' })}+ confirmLabel={t('widgets.generate.krea2RebalancePresetDelete')}+ isOpen={presetPendingDelete !== null}+ title={t('widgets.generate.krea2RebalancePresetDelete')}+ onClose={() => setPresetPendingDelete(null)}+ onConfirm={handleConfirmDelete}+ />+ </>+ );+};diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFamilyFields.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFamilyFields.tsxindex 07341ff82d..45b9488ecb 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFamilyFields.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFamilyFields.tsx@@ -2,12 +2,7 @@import type { GenerateModelConfig, GenerateSettings, Ideogram4SamplerPreset } from '@features/generation/core/types';import { Badge, createListCollection, Input, Stack, Switch } from '@chakra-ui/react';-import {- IDEOGRAM4_SAMPLER_PRESETS,- isValidKrea2RebalanceWeights,- KREA2_REBALANCE_WEIGHT_COUNT,- MAX_KREA2_SEED_VARIANCE_STRENGTH,-} from '@features/generation/core/settings';+import { IDEOGRAM4_SAMPLER_PRESETS, MAX_KREA2_SEED_VARIANCE_STRENGTH } from '@features/generation/core/settings';// Imported by subpath rather than from the `@platform/ui` barrel: the barrel is at its// direct-importer budget (a dev-invalidation limit), and depending on the two components// actually used means this module only rebuilds when those change.@@ -166,48 +161,13 @@ const Ideogram4Fields = ({ onCommit, settings }: Omit<GenerateModelFamilyFieldsP);};+// Conditioning rebalance used to live here; it now sits inline under Guidance in+// `GenerateConditioningRebalanceField`, where its bar editor has room to work.const Krea2Fields = ({ onCommit, settings }: Omit<GenerateModelFamilyFieldsProps, 'selectedModel'>) => {const { t } = useTranslation();- const weightsValid = isValidKrea2RebalanceWeights(settings.krea2RebalanceWeights);return (<Stack gap="2" p="2">- <Field label={t('widgets.generate.krea2Rebalance')} helpText={t('widgets.generate.krea2RebalanceHelp')}>- <FamilySwitch- checked={settings.krea2RebalanceEnabled}- label={t('widgets.generate.enabled')}- onCheckedChange={(checked) => onCommit({ krea2RebalanceEnabled: checked })}- />- </Field>- {settings.krea2RebalanceEnabled ? (- <>- <Field label={t('widgets.generate.krea2RebalanceMultiplier')}>- <SliderNumberField- ariaLabel={t('widgets.generate.krea2RebalanceMultiplier')}- max={10}- min={0}- step={0.1}- value={settings.krea2RebalanceMultiplier}- onChange={(value) => onCommit({ krea2RebalanceMultiplier: value })}- />- </Field>- <Field- label={t('widgets.generate.krea2RebalanceWeights')}- helpText={t('widgets.generate.krea2RebalanceWeightsHelp', { count: KREA2_REBALANCE_WEIGHT_COUNT })}- error={- weightsValid- ? undefined- : t('widgets.generate.krea2RebalanceWeightsInvalid', { count: KREA2_REBALANCE_WEIGHT_COUNT })- }- >- <Input- size="xs"- value={settings.krea2RebalanceWeights}- onChange={(event) => onCommit({ krea2RebalanceWeights: event.target.value })}- />- </Field>- </>- ) : null}<Field label={t('widgets.generate.krea2SeedVariance')} helpText={t('widgets.generate.krea2SeedVarianceHelp')}><FamilySwitchchecked={settings.krea2SeedVarianceEnabled}@@ -293,9 +253,6 @@ export const GenerateModelFamilyFields = ({ onCommit, selectedModel, settings }:const activeBadges = (<>- {base === 'krea-2' && settings.krea2RebalanceEnabled && (- <Badge size="xs">{t('widgets.generate.krea2Rebalance')}</Badge>- )}{base === 'krea-2' && settings.krea2SeedVarianceEnabled && (<Badge size="xs">{t('widgets.generate.krea2SeedVariance')}</Badge>)}diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsxindex 92beb58a4f..736c91d23f 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsx@@ -15,6 +15,7 @@ import { DicesIcon } from 'lucide-react';import { useId } from 'react';import { useTranslation } from 'react-i18next';+import { GenerateConditioningRebalanceField } from './GenerateConditioningRebalanceField';import { GenerationModelSelect as ModelSelect, useGenerationUi } from './GenerationUiContext';import { notifyGenerateModelSelectionCleared } from './modelSelectionNotice';import { GenerateCollapsibleSection } from './shared/GenerateCollapsibleSection';@@ -28,12 +29,14 @@ interface GenerateModelFieldsProps {models: readonly ModelConfig[];selectedModel: GenerateModelConfig | undefined;onCommit: (patch: Partial<GenerateSettings>) => void;+ onCommitImmediate: (patch: Partial<GenerateSettings>) => void;onCommitSettings: (nextSettings: GenerateSettings) => void;}export const GenerateModelFields = ({models,onCommit,+ onCommitImmediate,onCommitSettings,selectedModel,settings,@@ -118,6 +121,13 @@ export const GenerateModelFields = ({onChange={(cfgScale) => commitNumber('cfgScale', cfgScale)}/></Field>+ {selectedModel?.base === 'krea-2' ? (+ <GenerateConditioningRebalanceField+ settings={settings}+ onCommit={onCommit}+ onCommitImmediate={onCommitImmediate}+ />+ ) : null}{policy.ui.schedulerVisible ? (<Field hint="scheduler" label={t('widgets.generate.scheduler')}><HStack gap="1">diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.tsxindex c2f74a09be..22a7ccd90d 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.tsx@@ -256,6 +256,7 @@ export const GenerateSettingsForm = ({selectedModel={selectedModel}settings={draftSettings}onCommit={commit}+ onCommitImmediate={commitPatchImmediately}onCommitSettings={commitSettingsImmediately}/>diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceSparkline.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceSparkline.tsxnew file mode 100644index 0000000000..b6ba6a36db--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceSparkline.tsx@@ -0,0 +1,43 @@+import { chakra } from '@chakra-ui/react';+import { getRebalanceSparklinePath } from '@features/generation/core/conditioningRebalance';++const SPARKLINE_VIEW_WIDTH = 100;+const SPARKLINE_VIEW_HEIGHT = 14;+const SPARKLINE_RENDER_WIDTH = 56;++const SPARKLINE_STYLE = { display: 'block', flexShrink: 0, pointerEvents: 'none' } as const;++// Chakra-factory'd so `stroke` resolves through the theme, as the curve editor does.+// A raw `var(--chakra-colors-*)` only happens to work for palette tokens; a plain+// semantic token like `fg.muted` emits no such variable and the stroke silently+// resolves to `none`.+const SparklineSvg = chakra('svg');+const SparklinePath = chakra('path');++/**+ * The current curve at a glance, for the collapsed row. Decorative — the bar editor+ * below carries the accessible values, so this stays out of the accessibility tree.+ */+export const ConditioningRebalanceSparkline = ({ muted, weights }: { muted?: boolean; weights: readonly number[] }) => (+ <SparklineSvg+ aria-hidden+ // Sized with `h`/`w`, not the SVG `height`/`width` attributes: on a chakra-factory+ // element those are style props, and a bare `56` resolves to the spacing token+ // (14rem), not 56px.+ h={`${SPARKLINE_VIEW_HEIGHT}px`}+ preserveAspectRatio="none"+ style={SPARKLINE_STYLE}+ viewBox={`0 0 ${SPARKLINE_VIEW_WIDTH} ${SPARKLINE_VIEW_HEIGHT}`}+ w={`${SPARKLINE_RENDER_WIDTH}px`}+ >+ <SparklinePath+ d={getRebalanceSparklinePath(weights, SPARKLINE_VIEW_WIDTH, SPARKLINE_VIEW_HEIGHT)}+ fill="none"+ // Switched off, the curve is still worth reading — just not in the accent colour,+ // which is reserved for controls that are actually doing something.+ stroke={muted ? 'fg.muted' : 'accent.solid'}+ strokeWidth="1.5"+ vectorEffect="non-scaling-stroke"+ />+ </SparklineSvg>+);diff --git a/invokeai/frontend/webv2/src/platform/ui/hints/hintRegistry.ts b/invokeai/frontend/webv2/src/platform/ui/hints/hintRegistry.tsindex 0b974fc823..1bb2a9af8e 100644--- a/invokeai/frontend/webv2/src/platform/ui/hints/hintRegistry.ts+++ b/invokeai/frontend/webv2/src/platform/ui/hints/hintRegistry.ts@@ -32,6 +32,7 @@ export const FEATURE_HINTS = {clipSkip: { href: SUPPORT_ADVANCED_SETTINGS },colorCompensation: {},concepts: { href: SUPPORT_CONCEPTS },+ conditioningRebalance: {},creativity: {},guidance: {},height: {},