Skip to content

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.

feat(models): land model manager links on the relevant models

Josh Corbettd64e5fb95376
diff --git a/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx b/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx
index 71d28af075..c1756f9468 100644
--- a/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx
+++ b/invokeai/frontend/webv2/src/app/GenerationUiAdapter.tsx
@@ -159,9 +159,25 @@ export const GenerationUiAdapterProvider = ({ children }: { children: ReactNode
// Hash navigation, matching the app.selectModelsTab command. Going through
// useNavigate or the models UI store would pull either the router hooks or
// the store into the editor/launchpad initial bundles (architecture budget).
- // The manager opens on Add Models by default, which is where this link wants to land.
- openManager: () => {
- window.location.hash = `#/models?project=${encodeURIComponent(project.activeProjectId)}`;
+ // The manager opens on Add Models by default, which is where this link
+ // wants to land; a model type seeds its catalog filter through the same
+ // dynamic-import seam `WorkflowUiAdapter.openAddModels` uses, before the
+ // navigation, so the first paint is already filtered.
+ openManager: (options) => {
+ const navigateToManager = () => {
+ window.location.hash = `#/models?project=${encodeURIComponent(project.activeProjectId)}`;
+ };
+ const modelType = options?.modelType;
+
+ if (modelType === undefined) {
+ navigateToManager();
+ return;
+ }
+
+ void import('@features/models/launchpad').then(({ requestAddModelsTypeFilter }) => {
+ requestAddModelsTypeFilter(modelType);
+ navigateToManager();
+ });
},
status: modelsStatus,
}),
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelCard.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelCard.tsx
index e289a8a04d..73934ff6d8 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelCard.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelCard.tsx
@@ -15,7 +15,7 @@ import { isGenerateModelConfig, isVaeModelConfig } from '@features/generation/co
import { Button } from '@platform/ui/Button';
import { ConfirmDialog } from '@platform/ui/ConfirmDialog';
import { Field } from '@platform/ui/Field';
-import { useMemo, useState } from 'react';
+import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { GenerationModelSelect as ModelSelect, useGenerationUi } from './GenerationUiContext';
@@ -52,6 +52,7 @@ export const GenerateModelCard = ({
const { i18n, t } = useTranslation();
const ui = useGenerationUi();
const { openManager } = ui.models;
+ const openManagerForMainModels = useCallback(() => openManager({ modelType: 'main' }), [openManager]);
// A switch that clears incompatible settings waits behind a confirm. Only the
// model is held; the transition is recomputed against live settings on
// confirm, and the labels shown come from a preview run of the same move.
@@ -164,7 +165,7 @@ export const GenerateModelCard = ({
<Text color="fg.error" fontSize="2xs">
{t('widgets.generate.noSupportedModels')}
</Text>
- <Button alignSelf="flex-start" size="2xs" variant="outline" onClick={openManager}>
+ <Button alignSelf="flex-start" size="2xs" variant="outline" onClick={openManagerForMainModels}>
{t('widgets.generate.openModelManager')}
</Button>
</Stack>
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx
index 1658e01932..726f9bb912 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx
@@ -66,8 +66,11 @@ export interface GenerationUiAdapter {
error: string | null;
getBaseColorPalette(base: string): string;
getBaseLabel(base: string): string;
- /** Navigates to the model manager, which opens on Add Models by default. */
- openManager(): void;
+ /**
+ * Navigates to the model manager, which opens on Add Models by default;
+ * `modelType` pre-filters its starter catalog to the missing kind.
+ */
+ openManager(options?: { modelType?: string }): void;
status: 'error' | 'idle' | 'loaded' | 'loading';
};
notifications: {
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
index a922cb2a0b..e9258bd147 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx
@@ -50,12 +50,16 @@ const LLAVA_MODEL_TYPES = ['llava_onevision'];
* explained inside the popover rather than by disabling the trigger, so the
* dead end always has a door.
*/
-const OpenModelManagerButton = () => {
+const OpenModelManagerButton = ({ modelType }: { modelType?: string }) => {
const { t } = useTranslation();
const { openManager } = useGenerationUi().models;
+ const handleClick = useCallback(
+ () => openManager(modelType === undefined ? undefined : { modelType }),
+ [modelType, openManager]
+ );
return (
- <Button alignSelf="start" px="0" size="xs" variant="plain" onClick={openManager}>
+ <Button alignSelf="start" px="0" size="xs" variant="plain" onClick={handleClick}>
{t('widgets.generate.openModelManager')}
</Button>
);
@@ -493,7 +497,7 @@ const ExpandPromptButton = ({
<Text color="fg.subtle" fontSize="xs">
{t('widgets.generate.installTextLlmToExpandPrompts')}
</Text>
- <OpenModelManagerButton />
+ <OpenModelManagerButton modelType="text_llm" />
</>
) : (
<>
@@ -669,7 +673,7 @@ const ImageToPromptButton = ({
<Text color="fg.subtle" fontSize="xs">
{t('widgets.generate.installVisionModelToGeneratePrompts')}
</Text>
- <OpenModelManagerButton />
+ <OpenModelManagerButton modelType="llava_onevision" />
</>
) : (
<>
diff --git a/invokeai/frontend/webv2/src/features/models/launchpad.ts b/invokeai/frontend/webv2/src/features/models/launchpad.ts
index c431052074..5b3e2a81d1 100644
--- a/invokeai/frontend/webv2/src/features/models/launchpad.ts
+++ b/invokeai/frontend/webv2/src/features/models/launchpad.ts
@@ -10,4 +10,4 @@ export { ModelsNotice } from './ui/launchpad/ModelsNotice';
* only ever reached by `import()`, so seeding a search from the editor costs
* the editor nothing until someone clicks.
*/
-export { requestAddModelsSearch } from './ui/uiStore';
+export { requestAddModelsSearch, requestAddModelsTypeFilter } from './ui/uiStore';
diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.browser.test.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.browser.test.tsx
index 9424b38579..dcb31dcef6 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.browser.test.tsx
@@ -81,7 +81,7 @@ describe('AddModelsView search seed', () => {
document.body.append(host);
const store = await import('@features/models/ui/uiStore');
- store.clearAddModelsSeed();
+ store.clearAddModelsSeeds();
});
afterEach(() => {
diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsx
index 552b394508..b8353d8df4 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/AddModelsView.tsx
@@ -16,8 +16,9 @@ import {
} from '@features/models/data/externalProvidersStore';
import { ensureStartersLoaded, useStartersSelector } from '@features/models/data/startersStore';
import {
- clearAddModelsSeed,
+ clearAddModelsSeeds,
getAddModelsSeed,
+ getAddModelsTypeSeed,
openExternalProviderKeys,
openModelManagerTab,
updateModelsUi,
@@ -100,11 +101,17 @@ export const AddModelsView = () => {
),
[providerConfigs]
);
- const [starterFilters, setStarterFilters] = useState<StarterModelFilters>(DEFAULT_STARTER_MODEL_FILTERS);
+ const [starterFilters, setStarterFilters] = useState<StarterModelFilters>(() => {
+ const typeSeed = getAddModelsTypeSeed();
+
+ return typeSeed === null
+ ? DEFAULT_STARTER_MODEL_FILTERS
+ : { ...DEFAULT_STARTER_MODEL_FILTERS, typeFilter: typeSeed };
+ });
useMountEffect(() => {
- // One-shot: a seed only ever fills the box the view was opened with.
- clearAddModelsSeed();
+ // One-shot: a seed only ever fills the view it was opened with.
+ clearAddModelsSeeds();
ensureStartersLoaded();
const owner = captureAccountScope();
diff --git a/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.ts b/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.ts
index 1515a41627..5340169a2f 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.ts
+++ b/invokeai/frontend/webv2/src/features/models/ui/uiStore.test.ts
@@ -57,12 +57,30 @@ describe('models ui store', () => {
expect(store.getAddModelsSeed()).toBe('Juggernaut XL');
expect(store.getAddModelsSeed()).toBe('Juggernaut XL');
- store.clearAddModelsSeed();
+ store.clearAddModelsSeeds();
// The next time Add Models opens on its own, the box is empty again.
expect(store.getAddModelsSeed()).toBe('');
});
+ it('hands the starter type-filter seed over exactly once, and the two seeds displace each other', async () => {
+ const store = await import('./uiStore');
+
+ store.requestAddModelsTypeFilter('text_llm');
+ expect(store.getModelsUiSnapshotForTests().activeTab).toBe('add');
+ expect(store.getAddModelsTypeSeed()).toBe('text_llm');
+ expect(store.getAddModelsSeed()).toBe('');
+
+ store.requestAddModelsSearch('Juggernaut XL');
+ expect(store.getAddModelsTypeSeed()).toBeNull();
+
+ store.requestAddModelsTypeFilter('llava_onevision');
+ expect(store.getAddModelsSeed()).toBe('');
+
+ store.clearAddModelsSeeds();
+ expect(store.getAddModelsTypeSeed()).toBeNull();
+ });
+
it('keeps the bundle selection until it is explicitly replaced', async () => {
const store = await import('./uiStore');
diff --git a/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts b/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts
index 78e6e3bdc7..d79919813a 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts
+++ b/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts
@@ -1,4 +1,4 @@
-import type { FoundModel } from '@features/models/core/types';
+import type { FoundModel, ModelTaxonomyType } from '@features/models/core/types';
import { DEFAULT_LIBRARY_FILTERS, type ModelLibraryFilters } from '@features/models/core/library';
import { registerAccountOwnedResource } from '@platform/state/accountLifecycle';
@@ -31,11 +31,17 @@ export interface ModelsUiSnapshot {
/**
* A pending Add Models search, handed over by a surface outside the manager
* (see {@link requestAddModelsSearch}). Strictly one-shot: the view takes it
- * at mount and {@link clearAddModelsSeed} empties it, so the box keeps its own
- * local state and still resets when the view unmounts. `null` = nothing
+ * at mount and {@link clearAddModelsSeeds} empties it, so the box keeps its
+ * own local state and still resets when the view unmounts. `null` = nothing
* pending, which is not the same as a seeded empty string.
*/
addModelsSeed: string | null;
+ /**
+ * A pending starter-catalog type filter, one-shot exactly like
+ * {@link ModelsUiSnapshot.addModelsSeed} — for links that know what *kind* of
+ * model is missing rather than which one.
+ */
+ addModelsTypeSeed: ModelTaxonomyType | null;
/** Model focused in the manager library's detail pane. */
activeModelKey: string | null;
/**
@@ -66,6 +72,7 @@ const createInitialModelsUiSnapshot = (): ModelsUiSnapshot => ({
activeModelKey: null,
activeTab: 'add',
addModelsSeed: null,
+ addModelsTypeSeed: null,
filters: { ...DEFAULT_LIBRARY_FILTERS },
hfLookup: null,
highlightProviderId: null,
@@ -162,6 +169,24 @@ export const requestAddModelsSearch = (query: string): void => {
updateModelsUi({
activeTab: 'add',
addModelsSeed: query,
+ addModelsTypeSeed: null,
+ hfLookup: null,
+ scan: null,
+ selectedBundleName: null,
+ });
+};
+
+/**
+ * Open Add Models with the starter catalog filtered to one model type. The same
+ * navigate-from-elsewhere contract as {@link requestAddModelsSearch}, for links
+ * that know what kind of model is missing (prompt expansion needs a `text_llm`)
+ * rather than which one.
+ */
+export const requestAddModelsTypeFilter = (typeFilter: ModelTaxonomyType): void => {
+ updateModelsUi({
+ activeTab: 'add',
+ addModelsSeed: null,
+ addModelsTypeSeed: typeFilter,
hfLookup: null,
scan: null,
selectedBundleName: null,
@@ -171,16 +196,19 @@ export const requestAddModelsSearch = (query: string): void => {
/** Reads a pending seed without consuming it — safe to call from a `useState` initializer, which StrictMode double-invokes. */
export const getAddModelsSeed = (): string => store.getSnapshot().addModelsSeed ?? '';
+/** Pure read, like {@link getAddModelsSeed}. */
+export const getAddModelsTypeSeed = (): ModelTaxonomyType | null => store.getSnapshot().addModelsTypeSeed;
+
/**
- * Consumes the pending seed. Silent because the only reader took it in the same
- * commit and nothing subscribes to it: a notify here would be a store write
- * whose only effect is re-rendering the view that just read it.
+ * Consumes the pending seeds. Silent because the only reader took them in the
+ * same commit and nothing subscribes to them: a notify here would be a store
+ * write whose only effect is re-rendering the view that just read it.
*/
-export const clearAddModelsSeed = (): void => {
+export const clearAddModelsSeeds = (): void => {
const snapshot = store.getSnapshot();
- if (snapshot.addModelsSeed !== null) {
- store.setSnapshotSilently({ ...snapshot, addModelsSeed: null });
+ if (snapshot.addModelsSeed !== null || snapshot.addModelsTypeSeed !== null) {
+ store.setSnapshotSilently({ ...snapshot, addModelsSeed: null, addModelsTypeSeed: null });
}
};