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): persist conditioning rebalance presets per account
joshistoast6ca141f75846
diff --git a/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx b/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsxindex a2bf040ccf..ef755d196b 100644--- a/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx+++ b/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx@@ -4,6 +4,7 @@ import type { ReactNode } from 'react';import { getSelectedGalleryImageFromValues } from '@features/gallery/contracts';import { invalidateGallery } from '@features/gallery/queries';import { GenerationUiProvider } from '@features/generation/react';+import { normalizeRebalancePresets } from '@features/generation/settings';import { useAuthSession, useCapabilities } from '@features/identity';import { ensureModelsLoaded, getModelBaseColorPalette, getModelBaseLabel, useModelsSelector } from '@features/models';import { useQueryClient } from '@tanstack/react-query';@@ -102,6 +103,39 @@ export const GenerationUiAdapterProvider = ({ children }: { children: ReactNode}),[session.multiuserEnabled, session.user?.user_id]);+ const krea2RebalancePresets = useWorkbenchPreferenceSelector((preferences) => preferences.krea2RebalancePresets);+ const rebalancePresetsGroup = useMemo<GenerationUiAdapter['rebalancePresets']>(+ () => ({+ // Settings persists these shape-checked only; a curve whose weights no longer parse+ // (hand-edited storage, a future backend tap count) is dropped here rather than+ // handed to the picker.+ presets: normalizeRebalancePresets(krea2RebalancePresets),+ remove: (presetId) => {+ void patchWorkbenchPreferences({+ krea2RebalancePresets: getWorkbenchPreferences().krea2RebalancePresets.filter(+ (preset) => preset.id !== presetId+ ),+ });+ },+ rename: (presetId, label) => {+ void patchWorkbenchPreferences({+ krea2RebalancePresets: getWorkbenchPreferences().krea2RebalancePresets.map((preset) =>+ preset.id === presetId ? { ...preset, label } : preset+ ),+ });+ },+ save: (label, weights, multiplier) => {+ const preset = { id: crypto.randomUUID(), label, multiplier, weights };++ void patchWorkbenchPreferences({+ krea2RebalancePresets: [...getWorkbenchPreferences().krea2RebalancePresets, preset],+ });++ return preset;+ },+ }),+ [krea2RebalancePresets]+ );const generateSectionsOpen = useWorkbenchPreferenceSelector((preferences) => preferences.generateSectionsOpen);const sectionPreferencesGroup = useMemo<GenerationUiAdapter['sectionPreferences']>(() => ({@@ -125,6 +159,7 @@ export const GenerationUiAdapterProvider = ({ children }: { children: ReactNodenotifications: notificationsGroup,project,promptHistory: promptHistoryGroup,+ rebalancePresets: rebalancePresetsGroup,sectionPreferences: sectionPreferencesGroup,settings: settingsGroup,}),@@ -136,6 +171,7 @@ export const GenerationUiAdapterProvider = ({ children }: { children: ReactNodenotificationsGroup,project,promptHistoryGroup,+ rebalancePresetsGroup,sectionPreferencesGroup,settingsGroup,]diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsxindex c1ec29b8d4..0db776c4f4 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx@@ -1,4 +1,5 @@import type { GenerationModelCatalogItem, PromptHistoryItem } from '@features/generation/contracts';+import type { RebalancePreset } from '@features/generation/core/conditioningRebalance';import type { GenerateSettings } from '@features/generation/core/types';import type { ComponentType, ReactNode } from 'react';@@ -72,6 +73,14 @@ export interface GenerationUiAdapter {clear(): void;remove(prompt: PromptHistoryItem): void;};+ rebalancePresets: {+ /** User-saved conditioning rebalance curves; built-ins are not included. */+ presets: readonly RebalancePreset[];+ /** Adds a curve under a new id and returns it. */+ save(label: string, weights: string, multiplier: number): RebalancePreset;+ rename(presetId: string, label: string): void;+ remove(presetId: string): void;+ };sectionPreferences: {/** Persisted per-user open/closed overrides for panel sections; absent = section default. */sectionsOpen: Readonly<Record<string, boolean>>;diff --git a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts b/invokeai/frontend/webv2/src/workbench/settings/contracts.tsindex 659f1391f0..5e9859712b 100644--- a/invokeai/frontend/webv2/src/workbench/settings/contracts.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/contracts.ts@@ -13,6 +13,22 @@ export interface ProjectSettings {showPromptSyntaxHighlighting: boolean;}+/**+ * A saved conditioning-rebalance curve as it is persisted.+ *+ * Structurally the feature's `RebalancePreset`, declared here rather than imported:+ * these preferences load on the launchpad route, and a value import from+ * `@features/generation` would pull that feature's whole core into the initial bundle.+ * Settings stores the record; the generation feature owns what `weights` means and+ * re-validates it on read.+ */+export interface StoredRebalancePreset {+ id: string;+ label: string;+ weights: string;+ multiplier: number;+}+/** User-tunable appearance + behavior preferences surfaced in the Settings modal. */export interface WorkbenchPreferences {themeId: WorkbenchThemeId;@@ -41,4 +57,6 @@ export interface WorkbenchPreferences {customHotkeys: Record<string, string[]>;/** Generate panel section open/closed overrides keyed by section id; absent = section default. */generateSectionsOpen: Record<string, boolean>;+ /** User-saved Krea-2 conditioning rebalance curves, in the order they were saved. */+ krea2RebalancePresets: StoredRebalancePreset[];}diff --git a/invokeai/frontend/webv2/src/workbench/settings/store.ts b/invokeai/frontend/webv2/src/workbench/settings/store.tsindex 5667b666f5..55c58ee9a1 100644--- a/invokeai/frontend/webv2/src/workbench/settings/store.ts+++ b/invokeai/frontend/webv2/src/workbench/settings/store.ts@@ -1,5 +1,5 @@import type { DeveloperLogLevel, DeveloperLogNamespace } from '@workbench/diagnostics/contracts';-import type { ProjectSettings, WorkbenchPreferences } from '@workbench/settings/contracts';+import type { ProjectSettings, StoredRebalancePreset, WorkbenchPreferences } from '@workbench/settings/contracts';import { getUserStorageScope } from '@features/identity';import { normalizeWorkbenchLanguage } from '@platform/i18n/languages';@@ -59,6 +59,7 @@ export const DEFAULT_PREFERENCES: WorkbenchPreferences = {enableInformationalPopovers: true,enableModelDescriptions: true,generateSectionsOpen: {},+ krea2RebalancePresets: [],language: 'en',queueJobsScope: 'all',reduceMotion: false,@@ -161,6 +162,47 @@ const normalizeGenerateSectionsOpen = (values: unknown): Record<string, boolean>);};+/**+ * Shape-only: settings keeps the saved records intact and readable, and the generation+ * feature re-validates `weights` against the backend's grammar when it reads them+ * (`normalizeRebalancePresets`). Parsing here would mean importing that feature into the+ * launchpad bundle for no gain.+ */+const normalizeRebalancePresets = (values: unknown): StoredRebalancePreset[] => {+ if (!Array.isArray(values)) {+ return [];+ }++ const seen = new Set<string>();+ const presets: StoredRebalancePreset[] = [];++ for (const entry of values) {+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {+ continue;+ }++ const { id, label, multiplier, weights } = entry as Partial<StoredRebalancePreset>;++ if (+ typeof id !== 'string' ||+ id.trim() === '' ||+ seen.has(id) ||+ typeof label !== 'string' ||+ label.trim() === '' ||+ typeof weights !== 'string' ||+ typeof multiplier !== 'number' ||+ !Number.isFinite(multiplier)+ ) {+ continue;+ }++ seen.add(id);+ presets.push({ id, label: label.trim(), multiplier, weights });+ }++ return presets;+};+export const normalizeProjectSettings = (settings?: Partial<ProjectSettings>): ProjectSettings => ({antialiasProgressImages:typeof settings?.antialiasProgressImages === 'boolean'@@ -221,6 +263,7 @@ export const normalizeWorkbenchPreferences = (preferences?: WorkbenchPreferences? preferences.enableModelDescriptions: DEFAULT_PREFERENCES.enableModelDescriptions,generateSectionsOpen: normalizeGenerateSectionsOpen(preferences?.generateSectionsOpen),+ krea2RebalancePresets: normalizeRebalancePresets(preferences?.krea2RebalancePresets),language: normalizeWorkbenchLanguage(preferences?.language) ?? DEFAULT_PREFERENCES.language,queueJobsScope:preferences?.queueJobsScope === 'all-projects'