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(ui): open Add Models from the image map's missing-encoder link

Josh Corbett1186ad255d00
diff --git a/invokeai/frontend/webv2/src/features/models/index.ts b/invokeai/frontend/webv2/src/features/models/index.ts
index 0bd8cc08b5..c0f818e38c 100644
--- a/invokeai/frontend/webv2/src/features/models/index.ts
+++ b/invokeai/frontend/webv2/src/features/models/index.ts
@@ -30,4 +30,9 @@ export { useInstallActions } from './ui/add-models/useInstallActions';
export { getStarterModelInstallSources, type StarterInstallSource } from './ui/add-models/starterModelInstallSources';
export { ModelInstallRuntime } from './ui/ModelInstallRuntime';
export { ModelsPage } from './ui/ModelsPage';
-export { ModelsUiProvider, useOpenModelInManager, type ModelsUiAdapter } from './ui/ModelsUiContext';
+export {
+ ModelsUiProvider,
+ useOpenAddModelsSearch,
+ useOpenModelInManager,
+ type ModelsUiAdapter,
+} from './ui/ModelsUiContext';
diff --git a/invokeai/frontend/webv2/src/features/models/ui/ModelsUiContext.tsx b/invokeai/frontend/webv2/src/features/models/ui/ModelsUiContext.tsx
index 65825c544d..a6e54ae84f 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/ModelsUiContext.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/ModelsUiContext.tsx
@@ -44,3 +44,20 @@ export const useOpenModelInManager = (): ((modelKey: string) => void) | null =>
return canManageModels ? open : null;
};
+
+/** Opens Add Models searching the starter catalog for `query`, so the user reviews it before installing. */
+export const useOpenAddModelsSearch = (): ((query: string) => void) | null => {
+ const { canManageModels, managerProjectId } = useModelsUi();
+ const navigate = useNavigate();
+ const open = useCallback(
+ (query: string) => {
+ void import('./uiStore').then(({ requestAddModelsSearch }) => {
+ requestAddModelsSearch(query);
+ void navigate({ search: { project: managerProjectId ?? undefined }, to: '/models' });
+ });
+ },
+ [managerProjectId, navigate]
+ );
+
+ return canManageModels ? open : null;
+};
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts b/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts
index 3ff2a9c4f8..1124dad57c 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts
@@ -19,7 +19,7 @@ vi.mock('@platform/transport/http', () => ({
getApiErrorMessage: (_error: unknown, fallback: string) => fallback,
}));
-import type { ImageMapPoint } from './api';
+import type { ImageMapPoint, ImageMapPoints } from './api';
import { fetchImageMapPoints, fetchImageMapStatus, requestImageMapRefresh } from './api';
import { CLUSTER_PALETTE, getClusterColor, NOISE_COLOR } from './clusterPalette';
@@ -888,6 +888,17 @@ const EMPTY_SNAPSHOT = {
renderError: null,
} as const;
+const LOADED_POINTS: ImageMapPoints = {
+ clusterEps: null,
+ modelName: null,
+ pointCount: 0,
+ points: [],
+ stale: false,
+ state: 'ready',
+ updatedAt: null,
+ visibleHash: null,
+};
+
describe('image map status', () => {
beforeEach(() => {
mocks.apiFetchJson.mockReset();
@@ -1000,6 +1011,26 @@ describe('image index progress', () => {
expect(imageMapStore.getSnapshot().indexCounts).toEqual({ embedded: 70, failed: 0, pending: 30, total: 100 });
});
+ it('asks again on reopen while the map reports its encoder missing', async () => {
+ // The encoder is installed from the Model Manager, which unmounts the widget and its install watcher.
+ mocks.apiFetchJson.mockResolvedValue(BACKEND_RESPONSE);
+ imageMapStore.setSnapshot({
+ ...EMPTY_SNAPSHOT,
+ data: { ...LOADED_POINTS, modelName: 'encoder', state: 'model_missing' },
+ loadState: 'loaded',
+ });
+ ensureImageMapLoaded();
+
+ await vi.waitFor(() => expect(imageMapStore.getSnapshot().data?.state).toBe('ready'));
+ });
+
+ it('keeps loaded points on reopen', () => {
+ imageMapStore.setSnapshot({ ...EMPTY_SNAPSHOT, data: LOADED_POINTS, loadState: 'loaded' });
+ ensureImageMapLoaded();
+
+ expect(mocks.apiFetchJson).not.toHaveBeenCalledWith(expect.stringMatching(/^\/api\/v1\/image_map\/points/));
+ });
+
it('lets a later status fetch correct counts an event left stale', async () => {
// The run's final `pending: 0` report is lost while the socket is down, so
// without this the progress UI claims a finished backfill is still running
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts b/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts
index 9e3a5ab46f..999dc80fa3 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts
@@ -374,7 +374,11 @@ export const refreshImageIndexStatus = (): void => {
};
export const ensureImageMapLoaded = (): void => {
- if (imageMapStore.getSnapshot().loadState === 'idle') {
+ const { data, loadState } = imageMapStore.getSnapshot();
+
+ // A missing encoder is installed from the Model Manager, which unmounts this widget: ask again on every reopen
+ // rather than keep the retained diagnosis until someone presses Check again.
+ if (loadState === 'idle' || (data?.state === 'model_missing' && loadState !== 'loading')) {
void refreshImageMapPoints();
}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
index 6c9ebc3177..5cf2faab91 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
@@ -52,8 +52,9 @@ const models = vi.hoisted(() => {
return () => listeners.delete(listener);
},
},
+ canManageModels: true,
ensureStartersLoaded: vi.fn(),
- install: vi.fn((_request: { config?: unknown; source: string }) => Promise.resolve(true)),
+ openAddModelsSearch: vi.fn(),
};
});
@@ -65,13 +66,12 @@ vi.mock('@features/models', async (importOriginal) => {
ensureStartersLoaded: models.ensureStartersLoaded,
useActiveInstallSources: () =>
useSyncExternalStore(models.activeSources.subscribe, models.activeSources.get, models.activeSources.get),
- useInstallActions: () => ({ install: models.install, installMany: vi.fn(), pendingSources: EMPTY_SOURCES }),
+ useOpenAddModelsSearch: () => (models.canManageModels ? models.openAddModelsSearch : null),
useStartersSelector: (selector: (snapshot: unknown) => unknown) =>
selector({ response: { starter_models: STARTERS } }),
};
});
-const EMPTY_SOURCES: ReadonlySet<string> = new Set<string>();
const ENCODER_SOURCE = 'apple/DFN2B-CLIP-ViT-L-14-39B';
const ENCODER_DEPENDENCY_SOURCE = 'InvokeAI/encoder-preprocessor';
const STARTERS = [
@@ -199,6 +199,7 @@ beforeEach(() => {
registered.commands = [];
registered.hotkeys = [];
models.activeSources.set([]);
+ models.canManageModels = true;
host = document.createElement('div');
document.body.append(host);
root = createRoot(host);
@@ -248,8 +249,8 @@ describe('Image Map unavailable states', () => {
);
});
-describe('Image Map missing-model install link', () => {
- it('queues the starter install for the configured encoder', async () => {
+describe('Image Map missing-model link', () => {
+ it('opens Add Models on the configured encoder instead of downloading it', async () => {
await renderState('model_missing', 'DFN2B-CLIP-ViT-L-14-39B');
expect(host?.textContent).toContain(
@@ -260,34 +261,19 @@ describe('Image Map missing-model install link', () => {
expect(link?.textContent).toBe('DFN2B-CLIP-ViT-L-14-39B');
- await act(async () => {
- link?.click();
- await Promise.resolve();
- });
+ await act(() => link?.click());
- expect(models.install).toHaveBeenCalledWith(expect.objectContaining({ source: 'apple/DFN2B-CLIP-ViT-L-14-39B' }));
+ expect(models.openAddModelsSearch).toHaveBeenCalledWith('DFN2B-CLIP-ViT-L-14-39B');
});
- it('queues the starter dependencies ahead of the model itself', async () => {
+ it('leaves the encoder as plain text for a session that cannot manage models', async () => {
+ models.canManageModels = false;
await renderState('model_missing', 'DFN2B-CLIP-ViT-L-14-39B');
- await act(async () => {
- host?.querySelector('button')?.click();
- await Promise.resolve();
- });
-
- expect(models.install.mock.calls.map(([request]) => request.source)).toEqual([
- ENCODER_DEPENDENCY_SOURCE,
- ENCODER_SOURCE,
- ]);
- // The curated metadata rides along, so the model registers under its
- // starter identity instead of whatever probing guesses.
- expect(models.install).toHaveBeenLastCalledWith(
- expect.objectContaining({
- config: expect.objectContaining({ name: 'DFN2B-CLIP-ViT-L-14-39B', type: 'clip_vision' }),
- source: ENCODER_SOURCE,
- })
+ expect(host?.textContent).toContain(
+ 'install the image encoder model DFN2B-CLIP-ViT-L-14-39B from the Model Manager'
);
+ expect(buttonLabels()).toEqual(['Check again']);
});
it('reports an in-flight download instead of offering the install again', async () => {
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
index f94387dc3e..395cedd261 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
@@ -7,7 +7,7 @@ import {
ensureStartersLoaded,
getStarterModelInstallSources,
useActiveInstallSources,
- useInstallActions,
+ useOpenAddModelsSearch,
useStartersSelector,
} from '@features/models';
import { useMountEffect } from '@platform/react/useMountEffect';
@@ -171,9 +171,9 @@ export const ImageMapWidgetView = ({ runtime }: WidgetViewProps) => {
// Ahead of the loading spinner, unlike every other message: a refresh from
// this state flips `loadState` to `loading`, and flashing a spinner over the
- // message would unmount the install link — losing the in-flight download's
- // pending state and the "refresh when it lands" watcher with it. The
- // diagnosis is also what a refresh is least likely to change.
+ // message would unmount the model link — losing the "refresh when the
+ // download lands" watcher with it. The diagnosis is also what a refresh is
+ // least likely to change.
if (data?.state === 'model_missing') {
return (
<CenteredMessage
@@ -311,13 +311,13 @@ const CenteredMessage = ({
);
/**
- * Offer one-click encoder installation when the starter catalog resolves it; otherwise show text while unknown,
- * loading, or already downloading.
+ * Link the encoder to its Add Models entry, where the user reviews and installs it; plain text while the catalog
+ * does not carry it, while it downloads, or for sessions that cannot manage models.
*/
const ImageIndexModelInstallLink = ({ modelName }: { modelName: string }) => {
const starterModels = useStartersSelector(selectStarterModels);
const activeInstallSources = useActiveInstallSources();
- const { install, pendingSources } = useInstallActions();
+ const openAddModelsSearch = useOpenAddModelsSearch();
useMountEffect(() => {
ensureStartersLoaded();
@@ -329,9 +329,7 @@ const ImageIndexModelInstallLink = ({ modelName }: { modelName: string }) => {
return starter ? getStarterModelInstallSources(starter) : [];
}, [modelName, starterModels]);
- const installing = sources.some(
- (entry) => pendingSources.has(entry.source) || activeInstallSources.has(entry.source)
- );
+ const installing = sources.some((entry) => activeInstallSources.has(entry.source));
const wasInstalling = useRef(false);
// The server picks a freshly installed encoder up on the next map request,
@@ -345,25 +343,9 @@ const ImageIndexModelInstallLink = ({ modelName }: { modelName: string }) => {
wasInstalling.current = installing;
}, [installing]);
- const handleInstall = useCallback(() => {
- void (async () => {
- // Sequential, matching the Add Models starter path: the install queue is
- // ordered anyway, and a dependency must not race the model that needs it.
- for (const entry of sources) {
- // Re-checked here rather than trusted from the render that drew the
- // link: an install of the same source may have started elsewhere (the
- // Models page, another tab) in between, and queueing it twice
- // downloads it twice.
- if (pendingSources.has(entry.source) || activeInstallSources.has(entry.source)) {
- continue;
- }
-
- await install(entry);
- }
- })();
- }, [activeInstallSources, install, pendingSources, sources]);
+ const handleOpen = useCallback(() => openAddModelsSearch?.(modelName), [modelName, openAddModelsSearch]);
- if (sources.length === 0 || installing) {
+ if (sources.length === 0 || installing || !openAddModelsSearch) {
return (
<Text as="span" fontWeight="medium">
{modelName}
@@ -373,7 +355,7 @@ const ImageIndexModelInstallLink = ({ modelName }: { modelName: string }) => {
}
return (
- <Link as="button" colorPalette="accent" onClick={handleInstall} type="button" variant="underline">
+ <Link as="button" colorPalette="accent" onClick={handleOpen} type="button" variant="underline">
{modelName}
</Link>
);