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.

fix: reconcile command palette model selection and board access

joshistoastb13953f6f3d2
diff --git a/invokeai/app/api/routers/_access.py b/invokeai/app/api/routers/_access.py
index 1645542c9f..987e5ee077 100644
--- a/invokeai/app/api/routers/_access.py
+++ b/invokeai/app/api/routers/_access.py
@@ -83,14 +83,14 @@ def assert_board_read_access(board_id: str, current_user: CurrentUserOrDefault)
- The board visibility is Shared or Public.
- The board is explicitly shared with the user.
"""
- if current_user.is_admin:
- return
-
try:
board = ApiDependencies.invoker.services.boards.get_dto(board_id=board_id)
except Exception:
raise HTTPException(status_code=404, detail="Board not found")
+ if current_user.is_admin:
+ return
+
if board.user_id == current_user.user_id:
return
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index e23f26cc5c..32c60549f0 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -101,6 +101,7 @@
"identity",
"image-actions",
"index",
+ "modelSelectionNotice",
"models",
"nodeChrome",
"nodesStore",
@@ -205,6 +206,7 @@
"identity",
"image-actions",
"index",
+ "modelSelectionNotice",
"models",
"nodeChrome",
"nodesStore",
@@ -309,6 +311,7 @@
"identity",
"image-actions",
"index",
+ "modelSelectionNotice",
"models",
"nodeChrome",
"nodesStore",
@@ -411,6 +414,7 @@
"identity",
"image-actions",
"index",
+ "modelSelectionNotice",
"models",
"nodeChrome",
"nodesStore",
diff --git a/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json b/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json
index 496af1915a..019ea2ef3b 100644
--- a/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json
+++ b/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json
@@ -88,6 +88,7 @@
"canvasStagingView.ts": "workbench",
"controlAdapters.ts": "workbench",
"focusRegions.tsx": "workbench",
+ "generationModelSelection.ts": "workbench",
"graphPreviewInvocation.ts": "workbench",
"graphSurfaces.ts": "workbench",
"graphContracts.ts": "workbench",
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
index 53d2578fa4..ab0b770515 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.test.ts
@@ -15,13 +15,13 @@ import {
getComponentSectionPolicy,
getAutoFlux2ComponentSourceModel,
getDefaultGenerateSettings,
+ getGenerateModelSelectionResult,
getGenerationDimensions,
getGenerationModelAvailabilityReasons,
getGenerationModelPolicy,
getGenerationValidationReasons,
getMaxReferenceImages,
getPromptPolicy,
- getSettingsWithCompatibleModelSelections,
getSettingsWithModelDefaults,
isReferenceImageSupported,
isSupportedGenerateModel,
@@ -418,7 +418,7 @@ describe('component policies', () => {
vae: sdxlVae,
});
- const result = getSettingsWithCompatibleModelSelections(settings, model, []);
+ const result = getGenerateModelSelectionResult({ currentValues: settings, model, models: [] });
expect(result.settings.modelKey).toBe(model.key);
expect(result.settings.loras.map((lora) => lora.model.key)).toEqual(['sdxl-lora']);
@@ -430,10 +430,65 @@ describe('component policies', () => {
expect(result.clearedLabels).toEqual(['LoRAs', 'T5 Encoder', 'CLIP skip', 'CFG rescale']);
});
+ it('initializes empty and malformed values from the selected model defaults', () => {
+ const model = createModel('cogview4', { default_settings: { steps: 17 } });
+
+ for (const currentValues of [{}, { batchCount: 8 }]) {
+ const result = getGenerateModelSelectionResult({ currentValues, model, models: [] });
+
+ expect(result.settings).toMatchObject({
+ batchCount: 1,
+ height: 1024,
+ modelKey: model.key,
+ steps: 17,
+ width: 1024,
+ });
+ expect(result.clearedLabels).toEqual([]);
+ }
+ });
+
+ it('preserves model-independent and compatible settings across a model selection', () => {
+ const model = createModel('sdxl', { key: 'sdxl-other' });
+ const settings = createSettings(createModel('sdxl'), {
+ batchCount: 4,
+ negativePrompt: 'blurry',
+ positivePrompt: 'a lighthouse',
+ seed: 1234,
+ shouldRandomizeSeed: false,
+ vae: sdxlVae,
+ });
+
+ const result = getGenerateModelSelectionResult({ currentValues: settings, model, models: [] });
+
+ expect(result.settings).toMatchObject({
+ batchCount: 4,
+ modelKey: model.key,
+ negativePrompt: 'blurry',
+ positivePrompt: 'a lighthouse',
+ seed: 1234,
+ shouldRandomizeSeed: false,
+ vae: sdxlVae,
+ });
+ expect(result.clearedLabels).toEqual([]);
+ });
+
+ it('applies automatic FLUX.2 component sources as part of model selection', () => {
+ const model = createModel('flux2', { format: 'gguf_quantized', variant: 'klein_9b' });
+ const source = createModel('flux2', { format: 'diffusers', key: 'flux2-source', variant: 'klein_9b' });
+
+ const result = getGenerateModelSelectionResult({
+ currentValues: createSettings(createModel('sdxl')),
+ model,
+ models: [source],
+ });
+
+ expect(result.settings.componentSourceModel).toBe(source);
+ });
+
it('reconciles dimensions to the new model grid when the selected model changes', () => {
const model = createModel('cogview4');
const settings = createSettings(createModel('sdxl'), { height: 520, width: 520 });
- const result = getSettingsWithCompatibleModelSelections(settings, model, []);
+ const result = getGenerateModelSelectionResult({ currentValues: settings, model, models: [] });
expect(result.settings.width).toBe(512);
expect(result.settings.height).toBe(512);
@@ -479,7 +534,7 @@ describe('component policies', () => {
vae: flux2Vae,
});
- const result = getSettingsWithCompatibleModelSelections(settings, model, []);
+ const result = getGenerateModelSelectionResult({ currentValues: settings, model, models: [] });
expect(result.settings.qwen3EncoderModel).toBeNull();
expect(result.settings.vae).toEqual(flux2Vae);
@@ -555,7 +610,11 @@ describe('component policies', () => {
],
});
- const result = getSettingsWithCompatibleModelSelections(settings, createModel('cogview4'), [sdxlIpAdapter]);
+ const result = getGenerateModelSelectionResult({
+ currentValues: settings,
+ model: createModel('cogview4'),
+ models: [sdxlIpAdapter],
+ });
expect(result.settings.referenceImages).toEqual([]);
expect(result.clearedLabels).toContain('Reference Images');
@@ -580,10 +639,11 @@ describe('component policies', () => {
],
});
- const result = getSettingsWithCompatibleModelSelections(settings, createModel('sd-1'), [
- sd1IpAdapter,
- sdxlIpAdapter,
- ]);
+ const result = getGenerateModelSelectionResult({
+ currentValues: settings,
+ model: createModel('sd-1'),
+ models: [sd1IpAdapter, sdxlIpAdapter],
+ });
expect(result.settings.referenceImages).toEqual([
{
@@ -612,7 +672,11 @@ describe('component policies', () => {
],
});
- const toSdxl = getSettingsWithCompatibleModelSelections(settings, sdxlModel, [sdxlIpAdapter]);
+ const toSdxl = getGenerateModelSelectionResult({
+ currentValues: settings,
+ model: sdxlModel,
+ models: [sdxlIpAdapter],
+ });
expect(toSdxl.settings.referenceImages[0]?.config).toMatchObject({
image: referenceImage,
@@ -620,7 +684,11 @@ describe('component policies', () => {
type: 'ip_adapter',
});
- const backToFlux2 = getSettingsWithCompatibleModelSelections(toSdxl.settings, flux2Model, [sdxlIpAdapter]);
+ const backToFlux2 = getGenerateModelSelectionResult({
+ currentValues: toSdxl.settings,
+ model: flux2Model,
+ models: [sdxlIpAdapter],
+ });
expect(backToFlux2.settings.referenceImages).toEqual([
{ id: 'ref-1', isEnabled: true, config: { image: referenceImage, type: 'flux2_reference_image' } },
@@ -645,9 +713,11 @@ describe('component policies', () => {
];
const settings = createSettings(createModel('sdxl'), { referenceImages });
- const result = getSettingsWithCompatibleModelSelections(settings, createModel('sdxl', { key: 'sdxl-other' }), [
- sdxlIpAdapter,
- ]);
+ const result = getGenerateModelSelectionResult({
+ currentValues: settings,
+ model: createModel('sdxl', { key: 'sdxl-other' }),
+ models: [sdxlIpAdapter],
+ });
expect(result.settings.referenceImages).toBe(referenceImages);
expect(result.clearedLabels).not.toContain('Reference Images');
diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
index 2dcbf70a5a..68660e215d 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
@@ -31,6 +31,7 @@ import {
clampDimension,
DEFAULT_REFERENCE_IMAGE_LIMIT,
deriveAspectRatioId,
+ isGenerateSettings,
isLoraCompatibleWithModel,
MAX_DIMENSION,
MIN_DIMENSION,
@@ -635,9 +636,9 @@ export interface ComponentSectionPolicy {
validate: (ctx: ComponentPolicyContext) => string[];
}
-export interface GenerateSettingsCompatibilityResult {
+export interface GenerateModelSelectionResult {
settings: GenerateSettings;
- clearedLabels: string[];
+ clearedLabels: readonly string[];
}
const TYPE_CLIP_EMBED: ModelTaxonomyType[] = ['clip_embed'];
@@ -1143,11 +1144,11 @@ export const getCompatibleReferenceImages = (
return didChange ? next : referenceImages;
};
-export const getSettingsWithCompatibleModelSelections = (
+const getSettingsWithCompatibleModelSelections = (
settings: GenerateSettings,
model: GenerateModelConfig,
models: readonly ReferenceModelCandidate[]
-): GenerateSettingsCompatibilityResult => {
+): GenerateModelSelectionResult => {
const nextSettings: GenerateSettings = { ...settings, modelKey: model.key };
const clearedLabels: string[] = [];
const compatibleLoras = settings.loras.filter((lora) => isLoraCompatibleWithModel(lora.model, model));
@@ -1230,6 +1231,36 @@ export const getSettingsWithCompatibleModelSelections = (
return { settings: nextSettings, clearedLabels };
};
+/**
+ * Canonical transition for every Generate model-selection entry point.
+ * Normalizes persisted values, reconciles incompatible selections, and applies
+ * automatic component-source policy before callers persist the result.
+ */
+export const getGenerateModelSelectionResult = ({
+ currentValues,
+ model,
+ models,
+}: {
+ currentValues: unknown;
+ model: GenerateModelConfig;
+ models: readonly ModelConfig[];
+}): GenerateModelSelectionResult => {
+ const currentSettings = isGenerateSettings(currentValues)
+ ? currentValues
+ : (normalizeGenerateSettings(currentValues) ?? getDefaultGenerateSettings(model));
+ const result = getSettingsWithCompatibleModelSelections(currentSettings, model, models);
+ const componentSourceModel = getAutoFlux2ComponentSourceModel(model, result.settings, models);
+
+ if (componentSourceModel === undefined || componentSourceModel?.key === result.settings.componentSourceModel?.key) {
+ return result;
+ }
+
+ return {
+ ...result,
+ settings: { ...result.settings, componentSourceModel },
+ };
+};
+
const hasModelKey = (models: readonly ModelConfig[], key: string, type?: string): boolean =>
models.some((model) => model.key === key && (!type || model.type === type));
diff --git a/invokeai/frontend/webv2/src/features/generation/react.ts b/invokeai/frontend/webv2/src/features/generation/react.ts
index c51d6ce0e5..17d35c7196 100644
--- a/invokeai/frontend/webv2/src/features/generation/react.ts
+++ b/invokeai/frontend/webv2/src/features/generation/react.ts
@@ -7,6 +7,7 @@ export { GenerationUiProvider, type GenerationUiAdapter } from './ui/GenerationU
export { flushGenerateDrafts, useRegisterGenerateDraftFlusher } from './ui/generateDraftRegistry';
export { useDebouncedDraftValue } from './ui/useDebouncedDraftValue';
export { createGenerateFormValuesSelector } from './ui/generateFormViewModel';
+export { notifyGenerateModelSelectionCleared } from './ui/modelSelectionNotice';
export { adjustFocusedPromptAttention } from './ui/promptFields/promptAttentionHotkeys';
export { focusPositivePrompt } from './ui/promptFields/promptFocus';
export { promptHistoryNavigation } from './ui/promptFields/promptHistoryNavigation';
diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.ts
index 8d9304b701..8c3c9c229c 100644
--- a/invokeai/frontend/webv2/src/features/generation/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts
@@ -34,6 +34,7 @@ export {
getCompatibleReferenceImages,
getDefaultGenerateSettings,
getDefaultReferenceImageConfig,
+ getGenerateModelSelectionResult,
getGenerationDimensions,
getGenerationModelAvailabilityReasons,
getGenerationUiPolicy,
@@ -45,6 +46,7 @@ export {
isReferenceImageSupported,
isSupportedGenerateModel,
SCHEDULER_OPTIONS,
+ type GenerateModelSelectionResult,
} from './core/baseGenerationPolicies';
export { isVaeCompatibleWithGenerateModel } from './core/componentCompatibility';
export { MIN_BATCH_COUNT, sanitizeBatchCount } from './core/batch';
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsx
index fe4254d3f9..71873f1518 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateModelFields.tsx
@@ -6,7 +6,7 @@ import { HStack, NumberInput, Stack, Switch } from '@chakra-ui/react';
import {
getDefaultGenerateSettings,
getGenerationModelPolicy,
- getSettingsWithCompatibleModelSelections,
+ getGenerateModelSelectionResult,
isGenerateModelSelectable,
} from '@features/generation/core/baseGenerationPolicies';
import { isGenerateModelConfig, SEED_MAX } from '@features/generation/core/settings';
@@ -16,13 +16,11 @@ import { useId } from 'react';
import { useTranslation } from 'react-i18next';
import { GenerationModelSelect as ModelSelect, useGenerationUi } from './GenerationUiContext';
+import { notifyGenerateModelSelectionCleared } from './modelSelectionNotice';
import { GenerateCollapsibleSection } from './shared/GenerateCollapsibleSection';
import { ModelDefaultButton } from './shared/ModelDefaultButton';
import { SliderNumberField } from './shared/SliderNumberField';
-const formatClearedSettings = (labels: readonly string[]) =>
- labels.length <= 1 ? labels[0] : `${labels.slice(0, -1).join(', ')} and ${labels[labels.length - 1]}`;
-
const STEPS_SLIDER_MAX = 100;
interface GenerateModelFieldsProps {
@@ -40,7 +38,7 @@ export const GenerateModelFields = ({
selectedModel,
settings,
}: GenerateModelFieldsProps) => {
- const { t } = useTranslation();
+ const { i18n, t } = useTranslation();
const { notifications } = useGenerationUi();
// The switch shares the seed Field.Root with the number input; an explicit id
// keeps its label bound to its own hidden input instead of the Field's control id.
@@ -63,20 +61,16 @@ export const GenerateModelFields = ({
};
const selectModel = (model: GenerateModelConfig) => {
- const result = getSettingsWithCompatibleModelSelections(settings, model, models);
+ const result = getGenerateModelSelectionResult({ currentValues: settings, model, models });
onCommitSettings(result.settings);
-
- if (result.clearedLabels.length > 0) {
- notifications.info(
- t('widgets.generate.incompatibleSettingsCleared'),
- t('widgets.generate.incompatibleSettingsClearedDescription', {
- count: result.clearedLabels.length,
- labels: formatClearedSettings(result.clearedLabels),
- name: model.name,
- })
- );
- }
+ notifyGenerateModelSelectionCleared({
+ clearedLabels: result.clearedLabels,
+ locale: i18n.resolvedLanguage,
+ modelName: model.name,
+ notifications,
+ t,
+ });
};
return (
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/modelSelectionNotice.test.ts b/invokeai/frontend/webv2/src/features/generation/ui/modelSelectionNotice.test.ts
new file mode 100644
index 0000000000..4a5083ca27
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/ui/modelSelectionNotice.test.ts
@@ -0,0 +1,73 @@
+import type { TFunction } from 'i18next';
+
+import { describe, expect, it, vi } from 'vitest';
+
+import { notifyGenerateModelSelectionCleared } from './modelSelectionNotice';
+
+const createTranslation = () =>
+ vi.fn((key: string, options?: Record<string, unknown>) => {
+ if (key === 'widgets.generate.incompatibleSettingsCleared') {
+ return 'Incompatible settings cleared';
+ }
+
+ return `${String(options?.labels)} ${Number(options?.count) === 1 ? 'was' : 'were'} not compatible with ${String(options?.name)}.`;
+ }) as unknown as TFunction;
+
+describe('notifyGenerateModelSelectionCleared', () => {
+ it('does not notify when no settings were cleared', () => {
+ const info = vi.fn();
+
+ notifyGenerateModelSelectionCleared({
+ clearedLabels: [],
+ locale: 'en',
+ modelName: 'FLUX',
+ notifications: { info },
+ t: createTranslation(),
+ });
+
+ expect(info).not.toHaveBeenCalled();
+ });
+
+ it('passes singular interpolation values to the translated notice', () => {
+ const info = vi.fn();
+ const t = createTranslation();
+
+ notifyGenerateModelSelectionCleared({
+ clearedLabels: ['LoRAs'],
+ locale: 'en',
+ modelName: 'FLUX',
+ notifications: { info },
+ t,
+ });
+
+ expect(t).toHaveBeenLastCalledWith('widgets.generate.incompatibleSettingsClearedDescription', {
+ count: 1,
+ labels: 'LoRAs',
+ name: 'FLUX',
+ });
+ expect(info).toHaveBeenCalledWith('Incompatible settings cleared', 'LoRAs was not compatible with FLUX.');
+ });
+
+ it('formats multiple labels with the resolved locale and plural interpolation', () => {
+ const info = vi.fn();
+ const t = createTranslation();
+
+ notifyGenerateModelSelectionCleared({
+ clearedLabels: ['Dimensions', 'LoRAs', 'VAE'],
+ locale: 'en',
+ modelName: 'FLUX',
+ notifications: { info },
+ t,
+ });
+
+ expect(t).toHaveBeenLastCalledWith('widgets.generate.incompatibleSettingsClearedDescription', {
+ count: 3,
+ labels: 'Dimensions, LoRAs, and VAE',
+ name: 'FLUX',
+ });
+ expect(info).toHaveBeenCalledWith(
+ 'Incompatible settings cleared',
+ 'Dimensions, LoRAs, and VAE were not compatible with FLUX.'
+ );
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/modelSelectionNotice.ts b/invokeai/frontend/webv2/src/features/generation/ui/modelSelectionNotice.ts
new file mode 100644
index 0000000000..079f0d8d9a
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/ui/modelSelectionNotice.ts
@@ -0,0 +1,34 @@
+import type { TFunction } from 'i18next';
+
+interface GenerateModelSelectionNotifier {
+ info(title: string, message?: string): void;
+}
+
+export const notifyGenerateModelSelectionCleared = ({
+ clearedLabels,
+ locale,
+ modelName,
+ notifications,
+ t,
+}: {
+ clearedLabels: readonly string[];
+ locale: string | undefined;
+ modelName: string;
+ notifications: GenerateModelSelectionNotifier;
+ t: TFunction;
+}): void => {
+ if (clearedLabels.length === 0) {
+ return;
+ }
+
+ const labels = new Intl.ListFormat(locale, { style: 'long', type: 'conjunction' }).format(clearedLabels);
+
+ notifications.info(
+ t('widgets.generate.incompatibleSettingsCleared'),
+ t('widgets.generate.incompatibleSettingsClearedDescription', {
+ count: clearedLabels.length,
+ labels,
+ name: modelName,
+ })
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/generationModelSelection.test.ts b/invokeai/frontend/webv2/src/workbench/generationModelSelection.test.ts
new file mode 100644
index 0000000000..8cda829437
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/generationModelSelection.test.ts
@@ -0,0 +1,84 @@
+import type {
+ GenerateModelConfig,
+ GenerateSettings,
+ LoraModelConfig,
+ VaeModelConfig,
+} from '@features/generation/contracts';
+
+import { getDefaultGenerateSettings } from '@features/generation/settings';
+import { describe, expect, it, vi } from 'vitest';
+
+import { selectProjectGenerateModel } from './generationModelSelection';
+
+const createModel = (base: string, key = `${base}-model`): GenerateModelConfig => ({
+ base,
+ key,
+ name: key,
+ type: 'main',
+});
+
+const createSettings = (model: GenerateModelConfig, overrides: Partial<GenerateSettings> = {}): GenerateSettings => ({
+ ...getDefaultGenerateSettings(model),
+ seed: 7,
+ shouldRandomizeSeed: false,
+ ...overrides,
+});
+
+const sdxlLora: LoraModelConfig = { base: 'sdxl', key: 'sdxl-lora', name: 'SDXL LoRA', type: 'lora' };
+const sdxlVae: VaeModelConfig = { base: 'sdxl', key: 'sdxl-vae', name: 'SDXL VAE', type: 'vae' };
+
+describe('selectProjectGenerateModel', () => {
+ it('atomically stores reconciled model settings and returns cleared labels', () => {
+ const currentModel = createModel('sdxl');
+ const model = createModel('flux');
+ const setSettings = vi.fn();
+ const currentValues = createSettings(currentModel, {
+ batchCount: 3,
+ loras: [{ isEnabled: true, model: sdxlLora, weight: 1 }],
+ positivePrompt: 'a lighthouse',
+ vae: sdxlVae,
+ });
+
+ const result = selectProjectGenerateModel({
+ currentValues,
+ generation: { setSettings },
+ model,
+ models: [currentModel, model, sdxlLora, sdxlVae],
+ projectId: 'project-1',
+ });
+
+ expect(setSettings).toHaveBeenCalledOnce();
+ expect(setSettings).toHaveBeenCalledWith(
+ expect.objectContaining({
+ batchCount: 3,
+ loras: [],
+ model,
+ modelKey: model.key,
+ positivePrompt: 'a lighthouse',
+ seed: 7,
+ vae: null,
+ }),
+ 'project-1'
+ );
+ expect(result.clearedLabels).toEqual(expect.arrayContaining(['LoRAs', 'VAE']));
+ });
+
+ it('initializes complete settings when the project has no Generate values', () => {
+ const model = createModel('sdxl');
+ const setSettings = vi.fn();
+
+ const result = selectProjectGenerateModel({
+ currentValues: {},
+ generation: { setSettings },
+ model,
+ models: [model],
+ projectId: 'project-empty',
+ });
+
+ expect(result.settings).toMatchObject({ height: 1024, modelKey: model.key, width: 1024 });
+ expect(setSettings).toHaveBeenCalledWith(
+ expect.objectContaining({ height: 1024, model, modelKey: model.key, width: 1024 }),
+ 'project-empty'
+ );
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/generationModelSelection.ts b/invokeai/frontend/webv2/src/workbench/generationModelSelection.ts
new file mode 100644
index 0000000000..f61733f5f4
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/generationModelSelection.ts
@@ -0,0 +1,25 @@
+import type { GenerateModelConfig, GenerationModelCatalogItem } from '@features/generation/contracts';
+import type { GenerateModelSelectionResult } from '@features/generation/settings';
+import type { WorkbenchGenerationCommands } from '@workbench/workbenchStore';
+
+import { getGenerateModelSelectionResult } from '@features/generation/settings';
+
+export const selectProjectGenerateModel = ({
+ currentValues,
+ generation,
+ model,
+ models,
+ projectId,
+}: {
+ currentValues: unknown;
+ generation: Pick<WorkbenchGenerationCommands, 'setSettings'>;
+ model: GenerateModelConfig;
+ models: readonly GenerationModelCatalogItem[];
+ projectId: string;
+}): GenerateModelSelectionResult => {
+ const result = getGenerateModelSelectionResult({ currentValues, model, models });
+
+ generation.setSettings({ ...result.settings, model }, projectId);
+
+ return result;
+};
diff --git a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsx b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsx
index 64714f05d2..9256e6dbf5 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPaletteDialog.tsx
@@ -4,13 +4,21 @@ import type { openWidgetPlacement as OpenWidgetPlacement } from '@workbench/widg
import type { getWidgetsForRegion as GetWidgetsForRegion } from '@workbench/widgetRegistry';
import type { TFunction } from 'i18next';
+import { flushGenerateDrafts, notifyGenerateModelSelectionCleared } from '@features/generation/react';
import { getPromptHistoryRecallPatch } from '@features/generation/settings';
import { useModelsSnapshot } from '@features/models';
import { getQueueQueryScope, getQueueReadModelOptions } from '@features/queue/queries';
import { queryClient } from '@platform/query/client';
+import { selectProjectGenerateModel } from '@workbench/generationModelSelection';
import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';
+import { useNotify } from '@workbench/useNotify';
import { getProjectWidgetValues } from '@workbench/widgetState';
-import { useActiveProjectSelector, useWorkbenchCommands, useWorkbenchExtensions } from '@workbench/WorkbenchContext';
+import {
+ useActiveProjectSelector,
+ useWorkbenchCommands,
+ useWorkbenchExtensions,
+ useWorkbenchQueries,
+} from '@workbench/WorkbenchContext';
import { useCallback, useMemo, useSyncExternalStore } from 'react';
import { useTranslation } from 'react-i18next';
@@ -66,6 +74,8 @@ const WorkbenchCommandPaletteDialog = ({
}) => {
const { i18n, t } = useTranslation();
const extensions = useWorkbenchExtensions();
+ const notify = useNotify();
+ const workbenchQueries = useWorkbenchQueries();
const modelsSnapshot = useModelsSnapshot();
const models = modelsSnapshot.status === 'loaded' ? modelsSnapshot.models : undefined;
const projectId = useActiveProjectSelector((project) => project.id);
@@ -126,7 +136,7 @@ const WorkbenchCommandPaletteDialog = ({
[preferences.queueJobsScope, projectId]
);
const providers = useMemo<PaletteSearchProvider[]>(() => {
- const { gallery, widgets } = workbenchCommands;
+ const { gallery, generation, widgets } = workbenchCommands;
const openWidget = (typeId: 'workflow' | 'gallery' | 'generate' | 'preview' | 'queue') =>
openWidgetPlacement({
getWidgetsForRegion,
@@ -150,7 +160,25 @@ const WorkbenchCommandPaletteDialog = ({
t,
}),
createModelsProvider({
- applyModel: (model) => widgets.patchValues('generate', { model, modelKey: model.key }, projectId),
+ applyModel: (model, catalogModels) => {
+ flushGenerateDrafts();
+ const project = workbenchQueries.getSnapshot().activeProject;
+ const result = selectProjectGenerateModel({
+ currentValues: getProjectWidgetValues(project, 'generate'),
+ generation,
+ model,
+ models: catalogModels,
+ projectId: project.id,
+ });
+
+ notifyGenerateModelSelectionCleared({
+ clearedLabels: result.clearedLabels,
+ locale: i18n.resolvedLanguage,
+ modelName: model.name,
+ notifications: notify,
+ t,
+ });
+ },
openGenerateWidget: () => openWidget('generate'),
openModelManager: () => void executeCommand('app.selectModelsTab'),
t,
@@ -195,6 +223,7 @@ const WorkbenchCommandPaletteDialog = ({
generateValues,
i18n.resolvedLanguage,
models,
+ notify,
getWidgetsForRegion,
openWidgetPlacement,
projectId,
@@ -204,6 +233,7 @@ const WorkbenchCommandPaletteDialog = ({
requestQueueItemReveal,
t,
workbenchCommands,
+ workbenchQueries,
]);
return (
diff --git a/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.test.ts b/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.test.ts
new file mode 100644
index 0000000000..a4196b37d6
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.test.ts
@@ -0,0 +1,77 @@
+import type { GenerationModelCatalogItem } from '@features/generation/contracts';
+import type { ModelConfig } from '@features/models';
+import type { TFunction } from 'i18next';
+
+import { describe, expect, it, vi } from 'vitest';
+
+const { ensureModelsLoaded, getModelsSnapshot } = vi.hoisted(() => ({
+ ensureModelsLoaded: vi.fn(() => Promise.resolve()),
+ getModelsSnapshot: vi.fn(),
+}));
+
+vi.mock('@features/models', () => ({
+ ensureModelsLoaded,
+ getModelBaseLabel: (base: string) => base,
+ getModelsSnapshot,
+}));
+
+import { createModelsProvider } from './paletteProviders';
+
+const model = (key: string, base: string, type = 'main'): ModelConfig =>
+ ({ base, key, name: key, type }) as unknown as ModelConfig;
+const t = ((key: string) => key) as TFunction;
+const searchContext = () => ({ signal: new AbortController().signal });
+
+describe('createModelsProvider', () => {
+ it('lists only supported Generate models and applies one before opening the widget', async () => {
+ const supported = model('supported-sdxl', 'sdxl');
+ const external = model('external-provider', 'external', 'external_image_generator');
+ const models = [
+ supported,
+ external,
+ model('refiner', 'sdxl-refiner'),
+ model('unknown', 'unknown'),
+ model('any', 'any'),
+ model('vae', 'sdxl', 'vae'),
+ ];
+ const order: string[] = [];
+ const applyModel = vi.fn((_selected: GenerationModelCatalogItem, _models: readonly ModelConfig[]) => {
+ order.push('apply');
+ });
+ const openGenerateWidget = vi.fn(() => {
+ order.push('open');
+ });
+ const openModelManager = vi.fn();
+ getModelsSnapshot.mockReturnValue({ models, status: 'loaded' });
+ const provider = createModelsProvider({ applyModel, openGenerateWidget, openModelManager, t });
+
+ const entries = await provider.search({ text: '' }, searchContext());
+
+ expect(entries.map((entry) => entry.title)).toEqual(['supported-sdxl', 'external-provider']);
+
+ entries[0]?.run();
+ expect(applyModel).toHaveBeenCalledWith(supported, models);
+ expect(order).toEqual(['apply', 'open']);
+
+ entries[0]?.secondary?.run();
+ expect(openModelManager).toHaveBeenCalledOnce();
+ });
+
+ it('retains model name and base text matching', async () => {
+ const models = [model('cinematic-xl', 'sdxl'), model('fast-flux', 'flux')];
+ getModelsSnapshot.mockReturnValue({ models, status: 'loaded' });
+ const provider = createModelsProvider({
+ applyModel: vi.fn(),
+ openGenerateWidget: vi.fn(),
+ openModelManager: vi.fn(),
+ t,
+ });
+
+ expect((await provider.search({ text: 'cinematic' }, searchContext())).map((entry) => entry.title)).toEqual([
+ 'cinematic-xl',
+ ]);
+ expect((await provider.search({ text: 'flux' }, searchContext())).map((entry) => entry.title)).toEqual([
+ 'fast-flux',
+ ]);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.ts b/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.ts
index eea9b84d95..2b78f13fd5 100644
--- a/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.ts
+++ b/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.ts
@@ -1,4 +1,5 @@
import type { GalleryBoard, GalleryImage } from '@features/gallery/contracts';
+import type { GenerateModelConfig } from '@features/generation/contracts';
import type { ModelConfig } from '@features/models';
import type { QueueReadModel } from '@features/queue/contracts';
import type { PromptHistoryItem } from '@workbench/projectContracts';
@@ -7,6 +8,7 @@ import type { TFunction } from 'i18next';
import { ALL_READABLE_BOARDS_ID, listGalleryImages } from '@features/gallery/paletteSearch';
import { galleryBoardsOptions } from '@features/gallery/queries';
import { focusPositivePrompt } from '@features/generation/react';
+import { isSupportedGenerateModel } from '@features/generation/settings';
import { ensureModelsLoaded, getModelBaseLabel, getModelsSnapshot } from '@features/models';
import { extractGenerationMeta, getResultImageName } from '@features/queue/contracts';
import { listLibraryWorkflows } from '@features/workflow/paletteSearch';
@@ -173,15 +175,13 @@ export const createPromptHistoryProvider = ({
},
});
-const GENERATE_MODEL_TYPES = new Set(['external_image_generator', 'main']);
-
export const createModelsProvider = ({
applyModel,
openGenerateWidget,
openModelManager,
t,
}: {
- applyModel: (model: ModelConfig) => void;
+ applyModel: (model: GenerateModelConfig, models: readonly ModelConfig[]) => void;
openGenerateWidget: () => void;
openModelManager: () => void;
t: TFunction;
@@ -197,9 +197,8 @@ export const createModelsProvider = ({
const models = snapshot.status === 'loaded' ? snapshot.models : [];
return models
- .filter(
- (model) => GENERATE_MODEL_TYPES.has(model.type) && matchesTerms(`${model.name} ${model.base}`, query.text)
- )
+ .filter(isSupportedGenerateModel)
+ .filter((model) => matchesTerms(`${model.name} ${model.base}`, query.text))
.map<PaletteEntry>((model) => ({
group: 'Models',
groupLabel: t('commandPalette.groups.models'),
@@ -207,8 +206,8 @@ export const createModelsProvider = ({
isPersistentRecent: false,
keywords: model.base,
run: () => {
+ applyModel(model, models);
openGenerateWidget();
- applyModel(model);
},
secondary: { label: t('commandPalette.actions.openModelManager'), run: openModelManager },
subtitle: getModelBaseLabel(model.base),
diff --git a/tests/app/routers/test_boards_multiuser.py b/tests/app/routers/test_boards_multiuser.py
index d72e252385..0d7c8c782f 100644
--- a/tests/app/routers/test_boards_multiuser.py
+++ b/tests/app/routers/test_boards_multiuser.py
@@ -431,6 +431,19 @@ def test_list_board_image_names_admin_can_access_any_board(client: TestClient, a
assert response.status_code == status.HTTP_200_OK
+def test_list_board_image_names_missing_board_returns_404_for_admin(
+ client: TestClient, admin_token: str, mock_invoker: Invoker
+):
+ """Admins must not enumerate image names for a board that does not exist."""
+ response = client.get(
+ "/api/v1/boards/missing-board/image_names",
+ headers={"Authorization": f"Bearer {admin_token}"},
+ )
+
+ assert response.status_code == status.HTTP_404_NOT_FOUND
+ mock_invoker.services.board_images.get_all_board_image_names_for_board.assert_not_called()
+
+
def test_list_board_image_names_none_board_no_auth_check(enable_multiuser_for_tests: Any, client: TestClient):
"""Test that listing image names for the 'none' board requires auth but no ownership check."""
# The 'none' board is the uncategorized images board — no ownership check needed,
diff --git a/tests/app/routers/test_images.py b/tests/app/routers/test_images.py
index f8acada675..d09fc87a51 100644
--- a/tests/app/routers/test_images.py
+++ b/tests/app/routers/test_images.py
@@ -48,17 +48,21 @@ def test_download_images_from_board_id_empty_image_name_list(
return BoardRecord(board_id="12345", board_name=expected_board_name, created_at="None", updated_at="None")
monkeypatch.setattr(mock_invoker.services.board_records, "get", mock_get)
+ mock_get_dto = MagicMock(return_value=object())
+ monkeypatch.setattr(mock_invoker.services.boards, "get_dto", mock_get_dto)
prepare_download_images_test(monkeypatch, mock_invoker)
response = client.post("/api/v1/images/download", json={"board_id": "test"})
json_response = response.json()
assert response.status_code == 202
assert json_response["bulk_download_item_name"] == "test.zip"
+ mock_get_dto.assert_called_once_with(board_id="test")
def prepare_download_images_test(monkeypatch: Any, mock_invoker: Invoker) -> None:
mock_deps = MockApiDependencies(mock_invoker)
monkeypatch.setattr("invokeai.app.api.routers.images.ApiDependencies", mock_deps)
+ monkeypatch.setattr("invokeai.app.api.routers._access.ApiDependencies", mock_deps)
monkeypatch.setattr("invokeai.app.api.auth_dependencies.ApiDependencies", mock_deps)
monkeypatch.setattr(
"invokeai.app.api.routers.images.ApiDependencies.invoker.services.bulk_download.generate_item_id",