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(models): streamline model controls
joshistoast5d3204483d1f
diff --git a/invokeai/frontend/webv2/src/features/models/core/library.test.ts b/invokeai/frontend/webv2/src/features/models/core/library.test.tsindex 97a8d1a681..ef4d4a0338 100644--- a/invokeai/frontend/webv2/src/features/models/core/library.test.ts+++ b/invokeai/frontend/webv2/src/features/models/core/library.test.ts@@ -108,16 +108,17 @@ describe('getModelPickerGroups', () => {expect(result.groups[0]?.models.map((m) => m.key)).toEqual(['c']);});- it('sorts picker results by taxonomy rank then name', () => {+ it('groups by (type, base) sorted by taxonomy rank, base display order, then name', () => {const result = getModelPickerGroups(library, {modelTypes: ['main', 'lora', 'vae'],searchTerm: '',});- expect(result.groups.map((group) => [group.type, group.models.map((m) => m.key)])).toEqual([- ['main', ['b', 'a']],- ['lora', ['c']],- ['vae', ['d']],+ expect(result.groups.map((group) => [group.key, group.models.map((m) => m.key)])).toEqual([+ ['main:sdxl', ['a']],+ ['main:flux', ['b']],+ ['lora:sd-1', ['c']],+ ['vae:any', ['d']],]);});@@ -136,7 +137,7 @@ describe('getModelPickerGroups', () => {searchTerm: '',});- expect(all.groups.flatMap((group) => group.models.map((m) => m.key))).toEqual(['b', 'a', 'c', 'd']);+ expect(all.groups.flatMap((group) => group.models.map((m) => m.key))).toEqual(['a', 'b', 'c', 'd']);});it('exposes availableBases that stay stable across search and base filtering', () => {diff --git a/invokeai/frontend/webv2/src/features/models/core/library.ts b/invokeai/frontend/webv2/src/features/models/core/library.tsindex 1cdf50d94c..c7eeb12b10 100644--- a/invokeai/frontend/webv2/src/features/models/core/library.ts+++ b/invokeai/frontend/webv2/src/features/models/core/library.ts@@ -48,12 +48,24 @@ export interface ModelPickerOptions {searchTerm: string;}+/**+ * Picker list group: one per (type, base) pair so items never need a per-row+ * base badge — the header renders the base (and, for multi-type pickers, the+ * type label) from `base`/`type`.+ */+export interface ModelPickerGroup {+ key: string;+ type: ModelTaxonomyType;+ base: string;+ models: ModelConfig[];+}+export interface ModelPickerResult {/** Distinct bases among candidates (pre-search, pre-base-filter), for chips. */availableBases: string[];/** Models available before text search, used for empty-state copy. */candidates: ModelConfig[];- groups: ModelGroup[];+ groups: ModelPickerGroup[];}const matchesSearch = (model: ModelConfig, searchTerm: string): boolean => {@@ -156,10 +168,31 @@ export const getModelPickerGroups = (models: ModelConfig[], options: ModelPicker.sort((a, b) =>getModelCategoryRank(a.type) - getModelCategoryRank(b.type) ||+ getBaseDisplayRank(String(a.base)) - getBaseDisplayRank(String(b.base)) ||+ String(a.base).localeCompare(String(b.base)) ||a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }));- return { availableBases, candidates, groups: groupModelsByType(visibleModels) };+ return { availableBases, candidates, groups: groupModelsForPicker(visibleModels) };+};++const groupModelsForPicker = (models: ModelConfig[]): ModelPickerGroup[] => {+ const groups = new Map<string, ModelPickerGroup>();++ for (const model of models) {+ const base = String(model.base);+ const key = `${model.type}:${base}`;+ const existing = groups.get(key);++ if (existing) {+ existing.models.push(model);+ } else {+ groups.set(key, { base, key, models: [model], type: model.type });+ }+ }++ // Insertion order already follows the sorted model list (category, base, name).+ return [...groups.values()];};/** Distinct bases present in a model list, for base filter menus. */@@ -174,19 +207,21 @@ const DEPRIORITIZED_BASES: ReadonlySet<string> = new Set(['any', 'external', 'un* registry order from `baseIdentity`, unknown bases come next, and the* meaningless `any`/`external`/`unknown` bases are pushed to the very end.*/-export const collectBasesForDisplay = (models: Pick<ModelConfig, 'base'>[]): string[] => {- const bases = [...new Set(models.map((model) => String(model.base)))];- const rank = (base: string): number => {- if (DEPRIORITIZED_BASES.has(base)) {- return KNOWN_MODEL_BASES.length + 1;- }+/** Display rank for a base: registry order, unknown bases next, meaningless bases last. */+const getBaseDisplayRank = (base: string): number => {+ if (DEPRIORITIZED_BASES.has(base)) {+ return KNOWN_MODEL_BASES.length + 1;+ }++ const index = KNOWN_MODEL_BASES.indexOf(base as (typeof KNOWN_MODEL_BASES)[number]);- const index = KNOWN_MODEL_BASES.indexOf(base as (typeof KNOWN_MODEL_BASES)[number]);+ return index === -1 ? KNOWN_MODEL_BASES.length : index;+};- return index === -1 ? KNOWN_MODEL_BASES.length : index;- };+export const collectBasesForDisplay = (models: Pick<ModelConfig, 'base'>[]): string[] => {+ const bases = [...new Set(models.map((model) => String(model.base)))];- return bases.sort((a, b) => rank(a) - rank(b) || a.localeCompare(b));+ return bases.sort((a, b) => getBaseDisplayRank(a) - getBaseDisplayRank(b) || a.localeCompare(b));};/** Distinct types present in a model list, in canonical order. */diff --git a/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsx b/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsxindex 3923dfb1e5..2c9b50a978 100644--- a/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsx@@ -23,6 +23,7 @@ import { useModelsUi } from '@features/models/ui/ModelsUiContext';import { useMountEffect } from '@platform/react/useMountEffect';import { Button, CloseButton, IconButton, Tooltip } from '@platform/ui';import { Link } from '@tanstack/react-router';+import { dropdownContent, dropdownGroupLabel, dropdownItem } from '@theme/recipes';import { BoxIcon, CheckIcon, ChevronDownIcon, RotateCcwIcon, SearchIcon, XIcon } from 'lucide-react';import { useDeferredValue, useMemo, useRef, useState } from 'react';@@ -203,15 +204,22 @@ export const ModelSelect = ({aria-invalid={invalid ? true : undefined}aria-haspopup="listbox"className={className}- colorPalette={invalid ? 'red' : isOpen ? 'accent' : 'bg'}+ borderColor={invalid ? undefined : isOpen ? 'accent.solid' : 'border'}+ colorPalette={invalid ? 'red' : 'gray'}disabled={disabled}justifyContent="space-between"minW="0"pe={canClear ? '7' : '2'}ps="2"size={size}+ transitionDuration="fast"+ transitionProperty="border-color, background"variant="outline"w="full"+ _hover={{+ bg: 'transparent',+ borderColor: invalid ? undefined : isOpen ? 'accent.solid' : 'border.emphasized',+ }}>{selectedModel ? (<ModelButtonContent model={selectedModel} />@@ -248,13 +256,9 @@ export const ModelSelect = ({<Portal><Popover.Positioner><Popover.Content- bg="bg.muted"- borderColor="border.emphasized"- borderRadius="lg"- borderWidth="1px"- boxShadow="lg"- color="fg"+ css={dropdownContent}maxH="min(18rem, var(--available-height))"+ maxW="min(24rem, calc(100vw - 1rem))"minW="min(18rem, calc(100vw - 1rem))"overflow="hidden"p="0"@@ -310,7 +314,7 @@ export const ModelSelect = ({<HStack borderTopWidth="1px" borderColor="border.subtle" /><ScrollArea.Root maxH="14rem" size="xs" variant="hover" w="full"><ScrollArea.Viewport maxH="inherit" w="full">- <ScrollArea.Content py="1" role="listbox" aria-label={`Available ${scopeLabel}`}>+ <ScrollArea.Content maxW="full" py="1" role="listbox" aria-label={`Available ${scopeLabel}`}>{loadStatus === 'idle' || loadStatus === 'loading' ? (<Text color="fg.subtle" fontSize="2xs" p="2">Loading models…@@ -335,19 +339,21 @@ export const ModelSelect = ({) : null}{loadStatus === 'loaded'? groups.map((group) => (- <Stack key={group.type} gap="0">- {modelTypes.length > 1 ? (- <Text- color="fg.subtle"- fontSize="2xs"- fontWeight="600"- letterSpacing="0.02em"- px="2"- py="1"- textTransform="uppercase"- >- {group.label}- </Text>+ <Stack key={group.key} gap="0">+ {groups.length > 1 ? (+ <HStack gap="1.5" px="2" py="1">+ {modelTypes.length > 1 ? (+ <Text css={dropdownGroupLabel}>{getModelTypePluralLabel(group.type)}</Text>+ ) : null}+ <Badge+ colorPalette={getModelBaseColorPalette(group.base)}+ fontSize="2xs"+ size="xs"+ variant="surface"+ >+ {getModelBaseLabel(group.base)}+ </Badge>+ </HStack>) : null}{group.models.map((model) => {const currentOptionIndex = optionIndex;@@ -363,19 +369,16 @@ export const ModelSelect = ({}}aria-selected={value === model.key}borderRadius="0"+ css={dropdownItem}gap="2"+ h="auto"justifyContent="start"- truncate+ minH="6"+ py="1"role="option"size="2xs"variant="ghost"w="full"- _highlighted={{ bg: 'bg.subtle' }}- _focusVisible={{- outline: '2px solid',- outlineColor: 'accent.solid',- outlineOffset: '-2px',- }}onClick={() => selectModel(model)}onKeyDown={(event) => {if (event.key === 'Escape') {@@ -488,6 +491,8 @@ const ModelButtonContent = ({ model }: { model: ModelConfig }) => (</HStack>);+// No per-item base badge: the list is grouped by (type, base), so the group+// header already carries that information.const ModelOptionContent = ({ enableDescription, model }: { enableDescription: boolean; model: ModelConfig }) => (<HStack flex="1" gap="2" minW="0" textAlign="left" w="full"><Stack flex="1" gap="0" minW="0">@@ -495,7 +500,7 @@ const ModelOptionContent = ({ enableDescription, model }: { enableDescription: b{model.name}</Text>{enableDescription && model.description ? (- <Text color="fg.subtle" fontSize="2xs" truncate>+ <Text color="fg.subtle" fontSize="2xs" lineClamp={2}>{model.description}</Text>) : null}@@ -503,14 +508,5 @@ const ModelOptionContent = ({ enableDescription, model }: { enableDescription: b<Text color="fg.subtle" flexShrink={0} fontSize="2xs">{formatBytes(model.file_size)}</Text>- <Badge- colorPalette={getModelBaseColorPalette(model.base)}- flexShrink={0}- fontSize="2xs"- size="xs"- variant="surface"- >- {getModelBaseLabel(model.base)}- </Badge></HStack>);diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsxindex 5e9a1609b3..2183440d2d 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx@@ -2,11 +2,11 @@import type { AnyModelDefaultSettings, ModelConfig } from '@features/models/core/types';import type { TFunction } from 'i18next';-import { Grid, HStack, Icon, NativeSelect, NumberInput, Stack, Switch, Text } from '@chakra-ui/react';+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 { Button, Combobox, FieldLabel, Panel } from '@platform/ui';+import { Button, Combobox, FieldLabel, Panel, Select } from '@platform/ui';import { MoveHorizontalIcon } from 'lucide-react';import { useMemo, useState, type ReactNode } from 'react';import { useTranslation } from 'react-i18next';@@ -129,22 +129,29 @@ const numberControl =</NumberInput.Root>);-const selectControl =- (options: string[]) => (value: unknown, setValue: (value: unknown) => void, disabled: boolean, _label: string) => (- <NativeSelect.Root disabled={disabled} size="sm">- <NativeSelect.Field- value={typeof value === 'string' ? value : ''}- onChange={(event) => setValue(event.currentTarget.value)}- >- {options.map((option) => (- <option key={option} value={option}>- {option}- </option>- ))}- </NativeSelect.Field>- <NativeSelect.Indicator />- </NativeSelect.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 })),+ });++ 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 schedulerControl =(options: { label: string; value: string }[]) =>diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelEditForm.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelEditForm.tsxindex cfbb8e4465..6c221264f1 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelEditForm.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelEditForm.tsx@@ -1,14 +1,15 @@/* 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 { ModelConfig, PredictionType } from '@features/models/core/types';-import { HStack, Input, NativeSelect, Stack, Text, Textarea } from '@chakra-ui/react';+import { createListCollection, HStack, Input, Stack, Text, Textarea } from '@chakra-ui/react';import { getModelBaseLabel } from '@features/models/core/baseIdentity';import { modelEditSchema, type ModelEditFormValues } from '@features/models/core/schemas';import { getModelTypeLabel, MODEL_CATEGORIES } from '@features/models/core/taxonomy';import { updateModel } from '@features/models/data/api';import { replaceModelInStore } from '@features/models/data/modelsStore';import { useZodForm } from '@platform/react/useZodForm';-import { Button, Field } from '@platform/ui';+import { Button, Field, Select } from '@platform/ui';+import { useMemo } from 'react';import { useTranslation } from 'react-i18next';const KNOWN_BASES = [@@ -27,6 +28,10 @@ const KNOWN_BASES = ['unknown',];+const MODEL_TYPE_COLLECTION = createListCollection({+ items: MODEL_CATEGORIES.map((category) => ({ label: getModelTypeLabel(category.type), value: category.type })),+});+/** Zod-validated editor for a model's identity fields. */type ModelEditTarget = Pick<ModelConfig,@@ -53,7 +58,25 @@ export const ModelEditForm = ({variant: model.variant ?? '',});- const bases = KNOWN_BASES.includes(String(model.base)) ? KNOWN_BASES : [String(model.base), ...KNOWN_BASES];+ const baseCollection = useMemo(() => {+ const bases = KNOWN_BASES.includes(String(model.base)) ? KNOWN_BASES : [String(model.base), ...KNOWN_BASES];++ return createListCollection({+ items: bases.map((base) => ({ label: getModelBaseLabel(base), value: base })),+ });+ }, [model.base]);+ const predictionTypeCollection = useMemo(+ () =>+ createListCollection({+ items: [+ { label: t('common.none'), value: '' },+ { label: 'epsilon', value: 'epsilon' },+ { label: 'v_prediction', value: 'v_prediction' },+ { label: 'sample', value: 'sample' },+ ],+ }),+ [t]+ );const handleSave = () =>form.handleSubmit(async (values) => {@@ -91,34 +114,34 @@ export const ModelEditForm = ({</Field><HStack align="start" gap="2"><Field error={form.errors.base} label={t('models.base')}>- <NativeSelect.Root size="sm">- <NativeSelect.Field- value={form.values.base}- onChange={(event) => form.setValue('base', event.currentTarget.value)}- >- {bases.map((base) => (- <option key={base} value={base}>- {getModelBaseLabel(base)}- </option>- ))}- </NativeSelect.Field>- <NativeSelect.Indicator />- </NativeSelect.Root>+ <Select+ aria-label={t('models.base')}+ collection={baseCollection}+ size="sm"+ value={[form.values.base]}+ onValueChange={({ value }) => {+ const base = value[0];++ if (base !== undefined) {+ form.setValue('base', base);+ }+ }}+ /></Field><Field error={form.errors.type} label={t('models.type')}>- <NativeSelect.Root size="sm">- <NativeSelect.Field- value={form.values.type}- onChange={(event) => form.setValue('type', event.currentTarget.value)}- >- {MODEL_CATEGORIES.map((category) => (- <option key={category.type} value={category.type}>- {getModelTypeLabel(category.type)}- </option>- ))}- </NativeSelect.Field>- <NativeSelect.Indicator />- </NativeSelect.Root>+ <Select+ aria-label={t('models.type')}+ collection={MODEL_TYPE_COLLECTION}+ size="sm"+ value={[form.values.type]}+ onValueChange={({ value }) => {+ const type = value[0];++ if (type !== undefined) {+ form.setValue('type', type);+ }+ }}+ /></Field></HStack><HStack align="start" gap="2">@@ -130,20 +153,19 @@ export const ModelEditForm = ({/></Field><Field error={form.errors.predictionType} label={t('models.predictionType')}>- <NativeSelect.Root size="sm">- <NativeSelect.Field- value={form.values.predictionType}- onChange={(event) =>- form.setValue('predictionType', event.currentTarget.value as ModelEditFormValues['predictionType'])+ <Select+ aria-label={t('models.predictionType')}+ collection={predictionTypeCollection}+ size="sm"+ value={[form.values.predictionType]}+ onValueChange={({ value }) => {+ const predictionType = value[0];++ if (predictionType !== undefined) {+ form.setValue('predictionType', predictionType as ModelEditFormValues['predictionType']);}- >- <option value="">{t('common.none')}</option>- <option value="epsilon">epsilon</option>- <option value="v_prediction">v_prediction</option>- <option value="sample">sample</option>- </NativeSelect.Field>- <NativeSelect.Indicator />- </NativeSelect.Root>+ }}+ /></Field></HStack><Field error={form.errors.sourceUrl} helpText={t('models.sourceUrlHelp')} label={t('models.sourceUrl')}>diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelImageUpload.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelImageUpload.tsxindex 022f2cb050..8f5adef25c 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/ModelImageUpload.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/ModelImageUpload.tsx@@ -4,7 +4,7 @@ import type { ModelConfig } from '@features/models/core/types';import { Box, Flex, Icon, Image, Stack, Text } from '@chakra-ui/react';import { deleteModelImage, getModelImageUrl, updateModelImage } from '@features/models/data/api';import { markCoverImageChanged, useModelsSelector } from '@features/models/data/modelsStore';-import { IconButton, Tooltip } from '@platform/ui';+import { DropZone, IconButton, Tooltip } from '@platform/ui';import { ImageIcon, UploadIcon, XIcon } from 'lucide-react';import { useEffect, useRef, useState, type DragEvent } from 'react';import { useTranslation } from 'react-i18next';@@ -85,20 +85,18 @@ export const ModelImageUpload = ({};return (- <Box+ <DropZonearia-busy={isBusy || undefined}aria-label={t('models.uploadCoverImageFor', { name: model.name })}- bg="bg.emphasized"- borderColor={isDropActive ? 'accent.solid' : 'border.subtle'}+ bg={isDropActive ? 'accent.muted' : 'bg.emphasized'}borderStyle={hasImage ? 'solid' : 'dashed'}- borderWidth={isDropActive ? '2px' : '1px'}boxSize="24"cursor="pointer"flexShrink={0}+ isOver={isDropActive}overflow="hidden"position="relative"role="button"- rounded="lg"tabIndex={0}className="group"_focusVisible={{ outline: '2px solid {colors.accent.solid}', outlineOffset: '2px' }}@@ -214,7 +212,7 @@ export const ModelImageUpload = ({</Tooltip></Box>) : null}- </Box>+ </DropZone>);};/* 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 */