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
refactor(ui): split default-settings policy from rendering
Josh Corbette6e6e06cc92c
diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsxindex b792b9d40c..33e7d7de44 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx@@ -1,325 +1,123 @@/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */-import type { AnyModelDefaultSettings, ModelConfig } from '@features/models/core/types';-import type { TFunction } from 'i18next';+import type { AnyModelDefaultSettings } from '@features/models/core/types';import { createListCollection, Grid, HStack, Icon, NumberInput, Stack, Switch, Text } from '@chakra-ui/react';-import { loraDefaultSettingsSchema, mainDefaultSettingsSchema } from '@features/models/core/schemas';import { updateModel } from '@features/models/data/api';import { replaceModelInStore } from '@features/models/data/modelsStore';import { useScopedAction } from '@features/models/ui/shared/useScopedAction';import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';import { Button, Combobox, FieldLabel, Panel, Select } from '@platform/ui';import { MoveHorizontalIcon } from 'lucide-react';-import { useMemo, useState, type ReactNode } from 'react';+import { useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';+import type { DefaultSettingsControl, DefaultSettingsModel } from './defaultSettingsFields';++import { getFieldsForModel, validateDefaults } from './defaultSettingsFields';+/*** Per-model generation defaults ("use these settings when this model is* selected"). Every field is individually toggleable: off = inherit the app- * default (stored as null). Validation runs through zod on save.+ * default (stored as null). Field policy and validation live in+ * `defaultSettingsFields.ts`; this file only renders and saves.*/-const SCHEDULERS = [- 'ddim',- 'ddpm',- 'deis',- 'deis_k',- 'dpmpp_2s',- 'dpmpp_2s_k',- 'dpmpp_2m',- 'dpmpp_2m_k',- 'dpmpp_2m_sde',- 'dpmpp_2m_sde_k',- 'dpmpp_3m',- 'dpmpp_3m_k',- 'dpmpp_sde',- 'dpmpp_sde_k',- 'euler',- 'euler_k',- 'euler_a',- 'heun',- 'heun_k',- 'kdpm_2',- 'kdpm_2_k',- 'kdpm_2_a',- 'kdpm_2_a_k',- 'lcm',- 'lms',- 'lms_k',- 'pndm',- 'tcd',- 'unipc',- 'unipc_k',-];-const SCHEDULER_OPTIONS = SCHEDULERS.map((scheduler) => ({ label: scheduler, value: scheduler }));--const CONTROL_ADAPTER_TYPES = new Set(['controlnet', 't2i_adapter', 'control_lora']);--const PREPROCESSORS = [- 'canny_edge_detection',- 'color_map',- 'content_shuffle',- 'depth_anything_depth_estimation',- 'dw_openpose_detection',- 'hed_edge_detection',- 'lineart_anime_edge_detection',- 'lineart_edge_detection',- 'mediapipe_face_detection',- 'mlsd_detection',- 'normal_map',- 'pidi_edge_detection',- 'tile',-];--export type DefaultSettingsModel = Pick<ModelConfig, 'base' | 'default_settings' | 'key' | 'type'>;-interface DefaultSettingsDraft {modelKey: string;settings: AnyModelDefaultSettings;source: AnyModelDefaultSettings | null | undefined;}-export const supportsDefaultSettings = (model: Pick<ModelConfig, 'type'>): boolean =>- model.type === 'main' || model.type === 'lora' || CONTROL_ADAPTER_TYPES.has(model.type);--interface FieldSpec {- key: keyof AnyModelDefaultSettings;- labelKey: string;- /**- * Render the control; disabled (showing the inherited value) until customized. Omitted for a- * boolean default, where the row's own enable switch already expresses both states.- */- control?: (value: unknown, setValue: (value: unknown) => void, disabled: boolean, label: string) => ReactNode;- /** Value used when the toggle is switched on; also previewed while off. */- defaultValue: unknown;- /** Translation key for what applies while the toggle is off. */- inheritLabelKey: string;+interface FieldControlProps {+ control: DefaultSettingsControl;+ disabled: boolean;+ label: string;+ setValue: (value: unknown) => void;+ value: unknown;}-const numberControl =- (props: { max?: number; min?: number; step?: number }) =>- (value: unknown, setValue: (value: unknown) => void, disabled: boolean, _label: string) => (- <NumberInput.Root- disabled={disabled}- max={props.max}- min={props.min}- position="relative"- size="sm"- step={props.step ?? 1}- value={typeof value === 'number' ? String(value) : ''}- w="full"- onValueChange={(details) => {- // Empty/partial input is transient; only commit finite numbers so the- // field never silently flips back to "off".- if (Number.isFinite(details.valueAsNumber)) {- setValue(details.valueAsNumber);- }- }}- >- <NumberInput.Control />- {/* Drag horizontally on the handle to scrub the value. */}- <NumberInput.Scrubber- alignItems="center"- bottom="0"- cursor="ew-resize"- display="flex"- left="2"- position="absolute"- top="0"- zIndex={1}- >- <Icon as={MoveHorizontalIcon} boxSize="3" color="fg.subtle" />- </NumberInput.Scrubber>- <NumberInput.Input ps="7" />- </NumberInput.Root>- );--const selectControl = (options: string[]) => {- // Called only at module scope, so the collection is built once per field spec.- const collection = createListCollection({- items: options.map((option) => ({ label: option, value: option })),- });+// Built per option list; memoized by the rendering component per field key.+const buildCollection = (options: readonly string[]) =>+ createListCollection({ items: options.map((option) => ({ label: option, value: option })) });- return (value: unknown, setValue: (value: unknown) => void, disabled: boolean, label: string) => (- <Select- aria-label={label}- collection={collection}- disabled={disabled}- size="sm"- value={typeof value === 'string' ? [value] : []}- onValueChange={({ value: next }) => {- const nextValue = next[0];-- if (nextValue !== undefined) {- setValue(nextValue);- }- }}- />+const FieldControl = ({ control, disabled, label, setValue, value }: FieldControlProps) => {+ const selectCollection = useMemo(+ () => (control.kind === 'select' ? buildCollection(control.options) : null),+ [control]);-};--const schedulerControl =- (options: { label: string; value: string }[]) =>- (value: unknown, setValue: (value: unknown) => void, disabled: boolean, label: string) => (- <Combobox- aria-label={label}- disabled={disabled}- options={options}- size="sm"- value={typeof value === 'string' ? value : null}- onValueChange={setValue}- />+ const comboboxOptions = useMemo(+ () => (control.kind === 'combobox' ? control.options.map((option) => ({ label: option, value: option })) : null),+ [control]);-/**- * Stores model weights as fp8 on the compute device, trading a little quality for VRAM.- *- * No body control: `_should_use_fp8` only acts on `fp8_storage is True`, so an explicit `false`- * and an absent value behave identically. The row's enable switch already covers the two states- * that differ, and a second switch inside the card would imply a distinction that does not exist.- *- * The backend gates availability in `_should_use_fp8`; `supportsFp8Storage` mirrors those- * exclusions so the toggle is never offered where it would be silently ignored.- */-const FP8_STORAGE_FIELD: FieldSpec = {- defaultValue: true,- inheritLabelKey: 'models.defaultFieldInherited.fp8Storage',- key: 'fp8_storage',- labelKey: 'models.defaultFields.fp8Storage',-};--const MAIN_FIELDS: FieldSpec[] = [- {- control: schedulerControl(SCHEDULER_OPTIONS),- defaultValue: 'euler_a',- inheritLabelKey: 'models.defaultFieldInherited.scheduler',- key: 'scheduler',- labelKey: 'models.defaultFields.scheduler',- },- {- control: numberControl({ max: 10000, min: 1 }),- defaultValue: 30,- inheritLabelKey: 'models.defaultFieldInherited.steps',- key: 'steps',- labelKey: 'models.defaultFields.steps',- },- {- control: numberControl({ max: 200, min: 1, step: 0.5 }),- defaultValue: 7,- inheritLabelKey: 'models.defaultFieldInherited.cfgScale',- key: 'cfg_scale',- labelKey: 'models.defaultFields.cfgScale',- },- {- control: numberControl({ max: 0.99, min: 0, step: 0.05 }),- defaultValue: 0,- inheritLabelKey: 'models.defaultFieldInherited.cfgRescale',- key: 'cfg_rescale_multiplier',- labelKey: 'models.defaultFields.cfgRescale',- },- {- control: numberControl({ max: 20, min: 1, step: 0.5 }),- defaultValue: 4,- inheritLabelKey: 'models.defaultFieldInherited.guidance',- key: 'guidance',- labelKey: 'models.defaultFields.guidance',- },- {- control: numberControl({ max: 8192, min: 64, step: 8 }),- defaultValue: 1024,- inheritLabelKey: 'models.defaultFieldInherited.width',- key: 'width',- labelKey: 'models.defaultFields.width',- },- {- control: numberControl({ max: 8192, min: 64, step: 8 }),- defaultValue: 1024,- inheritLabelKey: 'models.defaultFieldInherited.height',- key: 'height',- labelKey: 'models.defaultFields.height',- },- {- control: selectControl(['fp16', 'fp32']),- defaultValue: 'fp16',- inheritLabelKey: 'models.defaultFieldInherited.vaePrecision',- key: 'vae_precision',- labelKey: 'models.defaultFields.vaePrecision',- },-];--const LORA_FIELDS: FieldSpec[] = [- {- control: numberControl({ max: 10, min: -10, step: 0.05 }),- defaultValue: 0.75,- inheritLabelKey: 'models.defaultFieldInherited.weight',- key: 'weight',- labelKey: 'models.defaultFields.weight',- },-];--const CONTROL_ADAPTER_FIELDS: FieldSpec[] = [- {- control: selectControl(PREPROCESSORS),- defaultValue: 'canny_edge_detection',- inheritLabelKey: 'models.defaultFieldInherited.preprocessor',- key: 'preprocessor',- labelKey: 'models.defaultFields.preprocessor',- },-];--/**- * Mirrors the backend's `_should_use_fp8` exclusions:- * - Z-Image: diffusers' layerwise casting hits a dtype mismatch on skipped modules.- * - LoRA / ControlLoRA: patched into a base model rather than run as their own forward pass, so- * the casting hooks would never fire.- * VAEs are excluded too, but they have no default-settings section at all.- */-export const supportsFp8Storage = (model: Pick<ModelConfig, 'base' | 'type'>): boolean => {- if (model.base === 'z-image') {- return false;- }-- return model.type === 'main' || model.type === 'controlnet' || model.type === 't2i_adapter';-};--export const getFieldsForModel = (model: Pick<ModelConfig, 'base' | 'type'>): FieldSpec[] => {- const fp8Fields = supportsFp8Storage(model) ? [FP8_STORAGE_FIELD] : [];-- if (model.type === 'main') {- return [...MAIN_FIELDS, ...fp8Fields];- }-- if (model.type === 'lora') {- return LORA_FIELDS;+ if (control.kind === 'number') {+ return (+ <NumberInput.Root+ disabled={disabled}+ max={control.max}+ min={control.min}+ position="relative"+ size="sm"+ step={control.step ?? 1}+ value={typeof value === 'number' ? String(value) : ''}+ w="full"+ onValueChange={(details) => {+ // Empty/partial input is transient; only commit finite numbers so the+ // field never silently flips back to "off".+ if (Number.isFinite(details.valueAsNumber)) {+ setValue(details.valueAsNumber);+ }+ }}+ >+ <NumberInput.Control />+ {/* Drag horizontally on the handle to scrub the value. */}+ <NumberInput.Scrubber+ alignItems="center"+ bottom="0"+ cursor="ew-resize"+ display="flex"+ left="2"+ position="absolute"+ top="0"+ zIndex={1}+ >+ <Icon as={MoveHorizontalIcon} boxSize="3" color="fg.subtle" />+ </NumberInput.Scrubber>+ <NumberInput.Input ps="7" />+ </NumberInput.Root>+ );}- return [...CONTROL_ADAPTER_FIELDS, ...fp8Fields];-};--const validateDefaults = (- model: Pick<ModelConfig, 'type'>,- settings: AnyModelDefaultSettings,- t: TFunction-): string | null => {- if (model.type === 'main') {- const result = mainDefaultSettingsSchema.safeParse({- cfgRescaleMultiplier: settings.cfg_rescale_multiplier ?? null,- cfgScale: settings.cfg_scale ?? null,- guidance: settings.guidance ?? null,- height: settings.height ?? null,- scheduler: settings.scheduler ?? null,- steps: settings.steps ?? null,- vaePrecision: settings.vae_precision ?? null,- width: settings.width ?? null,- });-- return result.success ? null : (result.error.issues[0]?.message ?? t('models.invalidDefaultSettings'));+ if (control.kind === 'select' && selectCollection) {+ return (+ <Select+ aria-label={label}+ collection={selectCollection}+ disabled={disabled}+ size="sm"+ value={typeof value === 'string' ? [value] : []}+ onValueChange={({ value: next }) => {+ const nextValue = next[0];++ if (nextValue !== undefined) {+ setValue(nextValue);+ }+ }}+ />+ );}- if (model.type === 'lora') {- const result = loraDefaultSettingsSchema.safeParse({ weight: settings.weight ?? null });-- return result.success ? null : (result.error.issues[0]?.message ?? t('models.invalidDefaultSettings'));+ if (control.kind === 'combobox' && comboboxOptions) {+ return (+ <Combobox+ aria-label={label}+ disabled={disabled}+ options={comboboxOptions}+ size="sm"+ value={typeof value === 'string' ? value : null}+ onValueChange={setValue}+ />+ );}return null;@@ -433,12 +231,15 @@ export const DefaultSettingsSection = ({<Switch.Label srOnly>{t('models.customizeDefaultField', { field: t(field.labelKey) })}</Switch.Label></Switch.Root></HStack>- {field.control?.(- isEnabled ? value : field.defaultValue,- (nextValue) => setFieldValue(field.key, nextValue),- !isEnabled,- t(field.labelKey)- )}+ {field.control ? (+ <FieldControl+ control={field.control}+ disabled={!isEnabled}+ label={t(field.labelKey)}+ setValue={(nextValue) => setFieldValue(field.key, nextValue)}+ value={isEnabled ? value : field.defaultValue}+ />+ ) : null}<Text color="fg.subtle" fontSize="2xs">{isEnabled ? t('models.customizedForThisModel') : t(field.inheritLabelKey)}</Text>diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsxindex 021387f031..f085f84024 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelDetail.tsx@@ -14,7 +14,8 @@ import { memo, useCallback, useState } from 'react';import { useTranslation } from 'react-i18next';import { SiHuggingface } from 'react-icons/si';-import { DefaultSettingsSection, supportsDefaultSettings, type DefaultSettingsModel } from './DefaultSettingsSection';+import { supportsDefaultSettings, type DefaultSettingsModel } from './defaultSettingsFields';+import { DefaultSettingsSection } from './DefaultSettingsSection';import { MissingFileBadge, ModelBaseBadge, ModelFormatBadge } from './ModelBadges';import { ModelEditForm } from './ModelEditForm';import { ModelImageUpload } from './ModelImageUpload';diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.tsindex 0ba27b209e..d46f116fd5 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts@@ -2,7 +2,7 @@ import type { ModelConfig } from '@features/models/core/types';import { describe, expect, it } from 'vitest';-import { getFieldsForModel, supportsFp8Storage } from './DefaultSettingsSection';+import { getFieldsForModel, supportsFp8Storage } from './defaultSettingsFields';const model = (base: string, type: string): Pick<ModelConfig, 'base' | 'type'> =>({ base, type }) as Pick<ModelConfig, 'base' | 'type'>;diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.ts b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.tsnew file mode 100644index 0000000000..6c3a8ae2f8--- /dev/null+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.ts@@ -0,0 +1,241 @@+import type { AnyModelDefaultSettings, ModelConfig } from '@features/models/core/types';+import type { TFunction } from 'i18next';++import { loraDefaultSettingsSchema, mainDefaultSettingsSchema } from '@features/models/core/schemas';++/**+ * The pure policy behind per-model default settings: which model types get the+ * section, which fields each type shows, and how drafts validate. The section+ * component renders these specs; control descriptors here stay declarative so+ * this module needs no React.+ */++export type DefaultSettingsModel = Pick<ModelConfig, 'base' | 'default_settings' | 'key' | 'type'>;++const CONTROL_ADAPTER_TYPES = new Set(['controlnet', 't2i_adapter', 'control_lora']);++export const supportsDefaultSettings = (model: Pick<ModelConfig, 'type'>): boolean =>+ model.type === 'main' || model.type === 'lora' || CONTROL_ADAPTER_TYPES.has(model.type);++const SCHEDULERS = [+ 'ddim',+ 'ddpm',+ 'deis',+ 'deis_k',+ 'dpmpp_2s',+ 'dpmpp_2s_k',+ 'dpmpp_2m',+ 'dpmpp_2m_k',+ 'dpmpp_2m_sde',+ 'dpmpp_2m_sde_k',+ 'dpmpp_3m',+ 'dpmpp_3m_k',+ 'dpmpp_sde',+ 'dpmpp_sde_k',+ 'euler',+ 'euler_k',+ 'euler_a',+ 'heun',+ 'heun_k',+ 'kdpm_2',+ 'kdpm_2_k',+ 'kdpm_2_a',+ 'kdpm_2_a_k',+ 'lcm',+ 'lms',+ 'lms_k',+ 'pndm',+ 'tcd',+ 'unipc',+ 'unipc_k',+];++const PREPROCESSORS = [+ 'canny_edge_detection',+ 'color_map',+ 'content_shuffle',+ 'depth_anything_depth_estimation',+ 'dw_openpose_detection',+ 'hed_edge_detection',+ 'lineart_anime_edge_detection',+ 'lineart_edge_detection',+ 'mediapipe_face_detection',+ 'mlsd_detection',+ 'normal_map',+ 'pidi_edge_detection',+ 'tile',+];++/** How the section renders a field's value; the component maps kind -> widget. */+export type DefaultSettingsControl =+ | { kind: 'number'; max?: number; min?: number; step?: number }+ | { kind: 'select'; options: readonly string[] }+ | { kind: 'combobox'; options: readonly string[] };++export interface FieldSpec {+ key: keyof AnyModelDefaultSettings;+ labelKey: string;+ /**+ * Omitted for a boolean default, where the row's own enable switch already+ * expresses both states.+ */+ control?: DefaultSettingsControl;+ /** Value used when the toggle is switched on; also previewed while off. */+ defaultValue: unknown;+ /** Translation key for what applies while the toggle is off. */+ inheritLabelKey: string;+}++/**+ * Stores model weights as fp8 on the compute device, trading a little quality for VRAM.+ *+ * No body control: `_should_use_fp8` only acts on `fp8_storage is True`, so an explicit `false`+ * and an absent value behave identically. The row's enable switch already covers the two states+ * that differ, and a second switch inside the card would imply a distinction that does not exist.+ *+ * The backend gates availability in `_should_use_fp8`; `supportsFp8Storage` mirrors those+ * exclusions so the toggle is never offered where it would be silently ignored.+ */+const FP8_STORAGE_FIELD: FieldSpec = {+ defaultValue: true,+ inheritLabelKey: 'models.defaultFieldInherited.fp8Storage',+ key: 'fp8_storage',+ labelKey: 'models.defaultFields.fp8Storage',+};++const MAIN_FIELDS: FieldSpec[] = [+ {+ control: { kind: 'combobox', options: SCHEDULERS },+ defaultValue: 'euler_a',+ inheritLabelKey: 'models.defaultFieldInherited.scheduler',+ key: 'scheduler',+ labelKey: 'models.defaultFields.scheduler',+ },+ {+ control: { kind: 'number', max: 10000, min: 1 },+ defaultValue: 30,+ inheritLabelKey: 'models.defaultFieldInherited.steps',+ key: 'steps',+ labelKey: 'models.defaultFields.steps',+ },+ {+ control: { kind: 'number', max: 200, min: 1, step: 0.5 },+ defaultValue: 7,+ inheritLabelKey: 'models.defaultFieldInherited.cfgScale',+ key: 'cfg_scale',+ labelKey: 'models.defaultFields.cfgScale',+ },+ {+ control: { kind: 'number', max: 0.99, min: 0, step: 0.05 },+ defaultValue: 0,+ inheritLabelKey: 'models.defaultFieldInherited.cfgRescale',+ key: 'cfg_rescale_multiplier',+ labelKey: 'models.defaultFields.cfgRescale',+ },+ {+ control: { kind: 'number', max: 20, min: 1, step: 0.5 },+ defaultValue: 4,+ inheritLabelKey: 'models.defaultFieldInherited.guidance',+ key: 'guidance',+ labelKey: 'models.defaultFields.guidance',+ },+ {+ control: { kind: 'number', max: 8192, min: 64, step: 8 },+ defaultValue: 1024,+ inheritLabelKey: 'models.defaultFieldInherited.width',+ key: 'width',+ labelKey: 'models.defaultFields.width',+ },+ {+ control: { kind: 'number', max: 8192, min: 64, step: 8 },+ defaultValue: 1024,+ inheritLabelKey: 'models.defaultFieldInherited.height',+ key: 'height',+ labelKey: 'models.defaultFields.height',+ },+ {+ control: { kind: 'select', options: ['fp16', 'fp32'] },+ defaultValue: 'fp16',+ inheritLabelKey: 'models.defaultFieldInherited.vaePrecision',+ key: 'vae_precision',+ labelKey: 'models.defaultFields.vaePrecision',+ },+];++const LORA_FIELDS: FieldSpec[] = [+ {+ control: { kind: 'number', max: 10, min: -10, step: 0.05 },+ defaultValue: 0.75,+ inheritLabelKey: 'models.defaultFieldInherited.weight',+ key: 'weight',+ labelKey: 'models.defaultFields.weight',+ },+];++const CONTROL_ADAPTER_FIELDS: FieldSpec[] = [+ {+ control: { kind: 'select', options: PREPROCESSORS },+ defaultValue: 'canny_edge_detection',+ inheritLabelKey: 'models.defaultFieldInherited.preprocessor',+ key: 'preprocessor',+ labelKey: 'models.defaultFields.preprocessor',+ },+];++/**+ * Mirrors the backend's `_should_use_fp8` exclusions:+ * - Z-Image: diffusers' layerwise casting hits a dtype mismatch on skipped modules.+ * - LoRA / ControlLoRA: patched into a base model rather than run as their own forward pass, so+ * the casting hooks would never fire.+ * VAEs are excluded too, but they have no default-settings section at all.+ */+export const supportsFp8Storage = (model: Pick<ModelConfig, 'base' | 'type'>): boolean => {+ if (model.base === 'z-image') {+ return false;+ }++ return model.type === 'main' || model.type === 'controlnet' || model.type === 't2i_adapter';+};++export const getFieldsForModel = (model: Pick<ModelConfig, 'base' | 'type'>): FieldSpec[] => {+ const fp8Fields = supportsFp8Storage(model) ? [FP8_STORAGE_FIELD] : [];++ if (model.type === 'main') {+ return [...MAIN_FIELDS, ...fp8Fields];+ }++ if (model.type === 'lora') {+ return LORA_FIELDS;+ }++ return [...CONTROL_ADAPTER_FIELDS, ...fp8Fields];+};++export const validateDefaults = (+ model: Pick<ModelConfig, 'type'>,+ settings: AnyModelDefaultSettings,+ t: TFunction+): string | null => {+ if (model.type === 'main') {+ const result = mainDefaultSettingsSchema.safeParse({+ cfgRescaleMultiplier: settings.cfg_rescale_multiplier ?? null,+ cfgScale: settings.cfg_scale ?? null,+ guidance: settings.guidance ?? null,+ height: settings.height ?? null,+ scheduler: settings.scheduler ?? null,+ steps: settings.steps ?? null,+ vaePrecision: settings.vae_precision ?? null,+ width: settings.width ?? null,+ });++ return result.success ? null : (result.error.issues[0]?.message ?? t('models.invalidDefaultSettings'));+ }++ if (model.type === 'lora') {+ const result = loraDefaultSettingsSchema.safeParse({ weight: settings.weight ?? null });++ return result.success ? null : (result.error.issues[0]?.message ?? t('models.invalidDefaultSettings'));+ }++ return null;+};