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
feat(webv2): improve gallery refresh and image recall
joshistoastf37f9d97eaa2
diff --git a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsxindex b8991df604..39d633a25c 100644--- a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx+++ b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx@@ -3,6 +3,7 @@ import { useEffect, useRef, useState, type Dispatch } from 'react';import type { Project, QueueItem } from './types';import type { WorkbenchAction } from './workbenchState';+import { getApiErrorMessage } from './backend/http';import {createQueueCoordinator,QueueItemCancelledError,@@ -22,7 +23,8 @@ const getSnapshotGalleryBoardId = (queueItem: QueueItem): string | null => {return typeof selectedBoardId === 'string' ? selectedBoardId : null;};-const toErrorMessage = (error: unknown): string => (error instanceof Error ? error.message : String(error));+const toErrorMessage = (error: unknown): string =>+ getApiErrorMessage(error, error instanceof Error ? error.message : String(error));const getSnapshotBatchCount = (queueItem: QueueItem): number => {const batchCount = queueItem.snapshot.widgetStates.generate?.values.batchCount;@@ -59,6 +61,9 @@ const routeRunResults = async (}dispatch({ images, projectId, queueItemId: queueItem.id, type: 'routeQueueItemResults' });+ if (queueItem.snapshot.destination === 'gallery') {+ dispatch({ type: 'refreshBackendData' });+ }} catch (error) {if (error instanceof QueueItemCancelledError) {dispatch({ projectId, queueItemId: queueItem.id, status: 'cancelled', type: 'setQueueItemStatus' });diff --git a/invokeai/frontend/webv2/src/workbench/gallery/api.ts b/invokeai/frontend/webv2/src/workbench/gallery/api.tsindex 82c4a60b23..e816fe0ba5 100644--- a/invokeai/frontend/webv2/src/workbench/gallery/api.ts+++ b/invokeai/frontend/webv2/src/workbench/gallery/api.ts@@ -138,6 +138,9 @@ const mapImage = (image: BackendImageDTO): GalleryImage => ({width: image.width,});+const normalizeTotal = (value: unknown, fallback: number): number =>+ typeof value === 'number' && Number.isFinite(value) ? Math.max(0, value) : Math.max(0, fallback);+export const listGalleryBoards = async ({includeArchived = false,orderBy = 'created_at',@@ -251,7 +254,7 @@ const listGalleryDateBoardImages = async ({);const images = await getGalleryImagesByNames(body.image_names.slice(offset, offset + limit));- return { images, total: body.total_count };+ return { images, total: normalizeTotal(body.total_count, body.image_names.length) };};export const listGalleryImages = async ({@@ -285,9 +288,16 @@ export const listGalleryImages = async ({search_term: searchTerm.trim() || undefined,starred_first: starredFirst,});- const body = await apiFetchJson<ListImagesResponse>(`/api/v1/images/?${query}`);-- return { images: body.items.map(mapImage), total: body.total };+ const body = await apiFetchJson<ListImagesResponse | BackendImageDTO[]>(`/api/v1/images/?${query}`);+ const items = Array.isArray(body) ? body : (body.items ?? []);++ return {+ images: items.map(mapImage),+ total: normalizeTotal(+ Array.isArray(body) ? undefined : body.total,+ offset + items.length + (Array.isArray(body) && items.length >= limit ? 1 : 0)+ ),+ };};export const getGalleryImageMetadata = async (imageName: string): Promise<GalleryImageMetadata | null> => {diff --git a/invokeai/frontend/webv2/src/workbench/generation/api.test.ts b/invokeai/frontend/webv2/src/workbench/generation/api.test.tsindex 35c973aee7..109ce2e556 100644--- a/invokeai/frontend/webv2/src/workbench/generation/api.test.ts+++ b/invokeai/frontend/webv2/src/workbench/generation/api.test.ts@@ -118,3 +118,43 @@ describe('enqueueWorkflowGraph', () => {expect(getSubmittedBody().batch.runs).toBe(10_000);});});++describe('getQueueItemResultImages', () => {+ beforeEach(() => {+ mocks.apiFetchJson.mockReset();+ });++ it('extracts image names from image collection outputs', async () => {+ mocks.apiFetchJson.mockImplementation((url: string) => {+ if (url === '/api/v1/queue/default/i/1') {+ return Promise.resolve({+ item_id: 1,+ session: {+ results: {+ external: {+ collection: [{ image_name: 'external-a.png' }, { image_name: 'external-b.png' }],+ },+ },+ },+ status: 'completed',+ });+ }++ const imageName = decodeURIComponent(url.replace('/api/v1/images/i/', ''));+ return Promise.resolve({+ height: 768,+ image_name: imageName,+ image_url: `/images/${imageName}`,+ is_intermediate: false,+ thumbnail_url: `/thumbs/${imageName}`,+ width: 1024,+ });+ });++ const { getQueueItemResultImages } = await import('./api');++ const images = await getQueueItemResultImages(1, 'source-1', '2026-06-15T00:00:00.000Z');++ expect(images.map((image) => image.imageName)).toEqual(['external-a.png', 'external-b.png']);+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/generation/api.ts b/invokeai/frontend/webv2/src/workbench/generation/api.tsindex 2e1b7bb33d..b1b3d9bdc2 100644--- a/invokeai/frontend/webv2/src/workbench/generation/api.ts+++ b/invokeai/frontend/webv2/src/workbench/generation/api.ts@@ -124,6 +124,20 @@ const getResultImageNames = (queueItem: QueueItemDTO): string[] => {if (typeof image?.image_name === 'string') {imageNames.add(image.image_name);}++ const collection = (result as { collection?: unknown }).collection;+ if (Array.isArray(collection)) {+ for (const item of collection) {+ if (!item || typeof item !== 'object') {+ continue;+ }++ const imageName = (item as { image_name?: unknown }).image_name;+ if (typeof imageName === 'string') {+ imageNames.add(imageName);+ }+ }+ }}return [...imageNames];diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.tsindex 9a52d124ae..a577a4d9bc 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts@@ -1,5 +1,10 @@import type { GalleryImage } from '@workbench/gallery/api';-import type { GenerateWidgetValues, MainModelConfig, VaeModelConfig } from '@workbench/generation/types';+import type {+ ComponentModelConfig,+ GenerateWidgetValues,+ MainModelConfig,+ VaeModelConfig,+} from '@workbench/generation/types';import { describe, expect, it } from 'vitest';@@ -7,7 +12,22 @@ import { buildImageRecallSettings, getImageRecallCapabilities } from './imageRecconst sdxlModel: MainModelConfig = { base: 'sdxl', key: 'sdxl-model', name: 'SDXL', type: 'main' };const sd1Model: MainModelConfig = { base: 'sd-1', key: 'sd1-model', name: 'SD 1.5', type: 'main' };+const animaModel: MainModelConfig = { base: 'anima', key: 'anima-model', name: 'Anima', type: 'main' };const vaeModel: VaeModelConfig = { base: 'sd-1', key: 'vae-model', name: 'SD 1.5 VAE', type: 'vae' };+const qwenImageVae: VaeModelConfig = { base: 'qwen-image', key: 'qwen-vae', name: 'Qwen VAE', type: 'vae' };+const animaQwen3: ComponentModelConfig = {+ base: 'any',+ key: 'anima-qwen3',+ name: 'Anima Qwen3',+ type: 'qwen3_encoder',+ variant: 'qwen3_06b',+};+const qwenVLEncoder: ComponentModelConfig = {+ base: 'any',+ key: 'qwen-vl',+ name: 'Qwen VL',+ type: 'qwen_vl_encoder',+};const createValues = (overrides: Partial<GenerateWidgetValues> = {}): GenerateWidgetValues => ({aspectRatioId: '1:1',@@ -16,18 +36,26 @@ const createValues = (overrides: Partial<GenerateWidgetValues> = {}): GenerateWibatchCount: 1,cfgRescaleMultiplier: 0,cfgScale: 7,+ clipEmbedModel: null,+ clipGEmbedModel: null,+ clipLEmbedModel: null,clipSkip: 0,+ componentSourceModel: null,height: 1024,+ loras: [],model: sdxlModel,modelKey: sdxlModel.key,negativePrompt: '',positivePrompt: '',+ qwen3EncoderModel: null,+ qwenVLEncoderModel: null,scheduler: 'euler_a',seamlessXAxis: false,seamlessYAxis: false,seed: 123,shouldRandomizeSeed: true,steps: 30,+ t5EncoderModel: null,vae: null,vaePrecision: 'fp32',width: 1024,@@ -69,6 +97,7 @@ describe('image recall', () => {image,kind: 'all',metadata,+ models: [sd1Model, vaeModel],supportedModels: [sd1Model],vaeModels: [vaeModel],});@@ -101,6 +130,7 @@ describe('image recall', () => {image,kind: 'remix',metadata,+ models: [sd1Model],supportedModels: [sd1Model],vaeModels: [],});@@ -117,6 +147,7 @@ describe('image recall', () => {image,kind: 'dimensions',metadata: null,+ models: [],supportedModels: [],vaeModels: [],});@@ -131,6 +162,7 @@ describe('image recall', () => {currentValues: createValues({ model: sdxlModel, modelKey: sdxlModel.key }),image,metadata: { clip_skip: 3 },+ models: [],supportedModels: [],vaeModels: [],});@@ -138,6 +170,7 @@ describe('image recall', () => {currentValues: createValues({ model: sd1Model, modelKey: sd1Model.key }),image,metadata: { clip_skip: 3 },+ models: [],supportedModels: [],vaeModels: [],});@@ -145,4 +178,66 @@ describe('image recall', () => {expect(sdxlCapabilities.clipSkip).toBe(false);expect(sd1Capabilities.clipSkip).toBe(true);});++ it('enables recall actions for component-only metadata', () => {+ const capabilities = getImageRecallCapabilities({+ currentValues: createValues(),+ image,+ metadata: { qwen3_encoder: { key: animaQwen3.key } },+ models: [animaQwen3],+ supportedModels: [],+ vaeModels: [],+ });++ expect(capabilities.all).toBe(true);+ expect(capabilities.remix).toBe(true);+ });++ it('recalls required component models for component-based families', () => {+ const result = buildImageRecallSettings({+ currentValues: createValues({ model: sd1Model, modelKey: sd1Model.key }),+ image,+ kind: 'all',+ metadata: {+ height: 1024,+ model: { key: animaModel.key },+ qwen3_encoder: { key: animaQwen3.key },+ vae: { key: qwenImageVae.key },+ width: 1024,+ },+ models: [animaModel, animaQwen3, qwenImageVae],+ supportedModels: [animaModel],+ vaeModels: [qwenImageVae],+ });++ expect(result?.values.model).toBe(animaModel);+ expect(result?.values.qwen3EncoderModel).toBe(animaQwen3);+ expect(result?.values.vae).toBe(qwenImageVae);+ expect(result?.fields).toContain('components');+ });++ it('clears component models when recalled metadata explicitly stores null', () => {+ const result = buildImageRecallSettings({+ currentValues: createValues({+ componentSourceModel: sd1Model,+ qwen3EncoderModel: animaQwen3,+ qwenVLEncoderModel: qwenVLEncoder,+ }),+ image,+ kind: 'all',+ metadata: {+ qwen3_encoder: null,+ qwen3_source: null,+ qwen_image_qwen_vl_encoder: null,+ },+ models: [sd1Model, animaQwen3, qwenVLEncoder],+ supportedModels: [],+ vaeModels: [],+ });++ expect(result?.values.componentSourceModel).toBeNull();+ expect(result?.values.qwen3EncoderModel).toBeNull();+ expect(result?.values.qwenVLEncoderModel).toBeNull();+ expect(result?.fields).toContain('components');+ });});diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.tsindex 59513e83ad..e2bee9d3fd 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts@@ -1,17 +1,26 @@import type { GalleryImage } from '@workbench/gallery/api';import type {+ ComponentModelConfig,+ GenerateModelConfig,GenerateWidgetValues,MainModelConfig,- SupportedGenerateBase,VaeModelConfig,} from '@workbench/generation/types';-import { getSettingsWithModelDefaults } from '@workbench/generation/graph';import {- CLIP_SKIP_MAX,+ getGenerationDimensions,+ getGenerationUiPolicy,+ getSettingsWithModelDefaults,+ isKnownScheduler,+} from '@workbench/generation/baseGenerationPolicies';+import { isVaeCompatibleWithGenerateModel } from '@workbench/generation/componentCompatibility';+import {+ cloneGenerateWidgetValues,+ getModelDefaultVae,+ isMainModelConfig,+ isModelIdentifierConfig,clampDimension,deriveAspectRatioId,- isKnownScheduler,SEED_MAX,} from '@workbench/generation/settings';@@ -45,7 +54,8 @@ type RecalledField =| 'cfg'| 'scheduler'| 'seamless'- | 'clipSkip';+ | 'clipSkip'+ | 'components';export interface ImageRecallResult {fields: RecalledField[];@@ -121,16 +131,16 @@ const getSeed = (metadata: unknown): number | null => {return seed !== null && seed >= 0 && seed <= SEED_MAX ? seed : null;};-const getDimension = (metadata: unknown, key: 'height' | 'width'): number | null => {+const getDimension = (metadata: unknown, key: 'height' | 'width', grid: number): number | null => {const dimension = getNumber(metadata, key);- return dimension !== null && dimension >= 64 ? clampDimension(dimension) : null;+ return dimension !== null && dimension >= 64 ? clampDimension(dimension, grid) : null;};-const getImageDimension = (image: GalleryImage, key: 'height' | 'width'): number | null => {+const getImageDimension = (image: GalleryImage, key: 'height' | 'width', grid: number): number | null => {const dimension = image[key];- return Number.isFinite(dimension) && dimension >= 64 ? clampDimension(dimension) : null;+ return Number.isFinite(dimension) && dimension >= 64 ? clampDimension(dimension, grid) : null;};const getSteps = (metadata: unknown): number | null => {@@ -165,22 +175,27 @@ const getClipSkip = (metadata: unknown): number | null => {return clipSkip !== null && clipSkip >= 0 ? clipSkip : null;};-const supportsClipSkip = (base: string): base is Exclude<SupportedGenerateBase, 'sdxl'> =>- base === 'sd-1' || base === 'sd-2';--const getClipSkipMax = (model: Pick<MainModelConfig, 'base'>): number | null =>- supportsClipSkip(model.base) ? CLIP_SKIP_MAX[model.base] : null;+const getClipSkipMax = (model: GenerateModelConfig): number | null =>+ getGenerationUiPolicy(model, { cfgScale: 1 }).clipSkipMax;-const getImageSize = (image: GalleryImage): Pick<GenerateWidgetValues, 'height' | 'width'> | null => {- const width = getImageDimension(image, 'width');- const height = getImageDimension(image, 'height');+const getImageSize = (+ image: GalleryImage,+ model: GenerateModelConfig+): Pick<GenerateWidgetValues, 'height' | 'width'> | null => {+ const grid = getGenerationDimensions(model).grid;+ const width = getImageDimension(image, 'width', grid);+ const height = getImageDimension(image, 'height', grid);return width !== null && height !== null ? { height, width } : null;};-const getMetadataSize = (metadata: unknown): Partial<Pick<GenerateWidgetValues, 'height' | 'width'>> => {- const width = getDimension(metadata, 'width');- const height = getDimension(metadata, 'height');+const getMetadataSize = (+ metadata: unknown,+ model: GenerateModelConfig+): Partial<Pick<GenerateWidgetValues, 'height' | 'width'>> => {+ const grid = getGenerationDimensions(model).grid;+ const width = getDimension(metadata, 'width', grid);+ const height = getDimension(metadata, 'height', grid);return {...(width !== null ? { width } : {}),@@ -194,15 +209,55 @@ const getMetadataModelKey = (metadata: unknown, key: 'model' | 'vae'): string |return typeof model?.key === 'string' ? model.key : null;};-const getSupportedMetadataModel = (metadata: unknown, supportedModels: MainModelConfig[]): MainModelConfig | null => {+const getSupportedMetadataModel = (+ metadata: unknown,+ supportedModels: GenerateModelConfig[]+): GenerateModelConfig | null => {const modelKey = getMetadataModelKey(metadata, 'model');return modelKey ? (supportedModels.find((model) => model.key === modelKey) ?? null) : null;};+const getModelFromMetadata = <T extends ComponentModelConfig>(+ metadata: unknown,+ key: string,+ models: readonly ComponentModelConfig[],+ guard: (model: unknown) => model is T+): T | null | undefined => {+ if (!isRecord(metadata) || !(key in metadata)) {+ return undefined;+ }++ if (metadata[key] === null) {+ return null;+ }++ const modelKey = getMetadataModelKey(metadata, key as 'model' | 'vae');++ if (!modelKey) {+ return undefined;+ }++ const model = models.find((candidate) => candidate.key === modelKey);++ return guard(model) ? model : undefined;+};++const getMetadataComponent = (+ metadata: unknown,+ key: string,+ models: readonly ComponentModelConfig[]+): ComponentModelConfig | null | undefined => getModelFromMetadata(metadata, key, models, isModelIdentifierConfig);++const getMetadataMainModel = (+ metadata: unknown,+ key: string,+ models: readonly ComponentModelConfig[]+): MainModelConfig | null | undefined => getModelFromMetadata(metadata, key, models, isMainModelConfig);+const getMetadataVae = (metadata: unknown,- model: MainModelConfig,+ model: GenerateModelConfig,vaeModels: VaeModelConfig[]): VaeModelConfig | null | undefined => {if (!isRecord(metadata) || !('vae' in metadata)) {@@ -219,13 +274,9 @@ const getMetadataVae = (return undefined;}- return vaeModels.find((vae) => vae.key === vaeKey && vae.base === model.base) ?? undefined;-};--const getDefaultVae = (model: MainModelConfig, vaeModels: VaeModelConfig[]): VaeModelConfig | null => {- const defaultVaeKey = model.default_settings?.vae;+ const vae = vaeModels.find((vae) => vae.key === vaeKey);- return defaultVaeKey ? (vaeModels.find((vae) => vae.key === defaultVaeKey && vae.base === model.base) ?? null) : null;+ return vae && isVaeCompatibleWithGenerateModel(model, vae) ? vae : undefined;};const getPromptPatch = (@@ -242,7 +293,8 @@ const getPromptPatch = (const hasPrompt = (metadata: unknown): boolean => Object.keys(getPromptPatch(metadata)).length > 0;-const hasMetadataSize = (metadata: unknown): boolean => Object.keys(getMetadataSize(metadata)).length > 0;+const hasMetadataSize = (metadata: unknown, model: GenerateModelConfig): boolean =>+ Object.keys(getMetadataSize(metadata, model)).length > 0;const hasGenerationSettings = (metadata: unknown): boolean =>getSteps(metadata) !== null ||@@ -252,6 +304,12 @@ const hasGenerationSettings = (metadata: unknown): boolean =>getBoolean(metadata, 'seamless_x') !== null ||getBoolean(metadata, 'seamless_y') !== null;+const hasComponentModels = (metadata: unknown, models: readonly ComponentModelConfig[]): boolean =>+ getMetadataMainModel(metadata, 'qwen3_source', models) !== undefined ||+ getMetadataMainModel(metadata, 'qwen_image_component_source', models) !== undefined ||+ getMetadataComponent(metadata, 'qwen3_encoder', models) !== undefined ||+ getMetadataComponent(metadata, 'qwen_image_qwen_vl_encoder', models) !== undefined;+const withDimensions = (values: GenerateWidgetValues,size: Partial<Pick<GenerateWidgetValues, 'height' | 'width'>>@@ -267,7 +325,7 @@ const withDimensions = (};};-const getSupportedClipSkip = (metadata: unknown, model: MainModelConfig): number | null => {+const getSupportedClipSkip = (metadata: unknown, model: GenerateModelConfig): number | null => {const clipSkip = getClipSkip(metadata);const clipSkipMax = getClipSkipMax(model);@@ -278,13 +336,15 @@ export const getImageRecallCapabilities = ({currentValues,image,metadata,+ models,supportedModels,vaeModels,}: {currentValues: GenerateWidgetValues;image: GalleryImage;metadata: unknown;- supportedModels: MainModelConfig[];+ supportedModels: GenerateModelConfig[];+ models: ComponentModelConfig[];vaeModels: VaeModelConfig[];}): ImageRecallCapabilities => {const supportedMetadataModel = getSupportedMetadataModel(metadata, supportedModels);@@ -293,16 +353,18 @@ export const getImageRecallCapabilities = ({const hasClipSkip = getSupportedClipSkip(metadata, clipSkipModel) !== null;const hasSeed = getSeed(metadata) !== null;const hasPrompts = hasPrompt(metadata);- const hasSize = hasMetadataSize(metadata);+ const hasSize = hasMetadataSize(metadata, currentValues.model);const hasSettings = hasGenerationSettings(metadata);+ const hasComponents = hasComponentModels(metadata, models);const hasModel = supportedMetadataModel !== null;- const hasAnyMetadata = hasModel || hasVae || hasPrompts || hasSeed || hasSize || hasSettings || hasClipSkip;- const hasNonSeedMetadata = hasModel || hasVae || hasPrompts || hasSize || hasSettings || hasClipSkip;+ const hasAnyMetadata =+ hasModel || hasVae || hasPrompts || hasSeed || hasSize || hasSettings || hasClipSkip || hasComponents;+ const hasNonSeedMetadata = hasModel || hasVae || hasPrompts || hasSize || hasSettings || hasClipSkip || hasComponents;return {all: hasAnyMetadata,clipSkip: getSupportedClipSkip(metadata, currentValues.model) !== null,- dimensions: getImageSize(image) !== null,+ dimensions: getImageSize(image, currentValues.model) !== null,prompts: hasPrompts,remix: hasNonSeedMetadata,seed: hasSeed,@@ -315,30 +377,48 @@ export const buildImageRecallSettings = ({kind,metadata,supportedModels,+ models,vaeModels,}: {currentValues: GenerateWidgetValues;image: GalleryImage;kind: ImageRecallKind;metadata: unknown;- supportedModels: MainModelConfig[];+ supportedModels: GenerateModelConfig[];+ models: ComponentModelConfig[];vaeModels: VaeModelConfig[];}): ImageRecallResult | null => {const fields: RecalledField[] = [];- let values: GenerateWidgetValues = {- ...currentValues,- model: { ...currentValues.model },- vae: currentValues.vae ? { ...currentValues.vae } : null,- };+ let values: GenerateWidgetValues = cloneGenerateWidgetValues(currentValues);if (kind === 'all' || kind === 'remix') {const model = getSupportedMetadataModel(metadata, supportedModels);if (model) {- values = { ...getSettingsWithModelDefaults(values, model), model, vae: getDefaultVae(model, vaeModels) };+ values = { ...getSettingsWithModelDefaults(values, model), model, vae: getModelDefaultVae(model, vaeModels) };fields.push('model');}+ const qwen3SourceModel = getMetadataMainModel(metadata, 'qwen3_source', models);+ const qwenImageSourceModel = getMetadataMainModel(metadata, 'qwen_image_component_source', models);+ const componentSourceModel = qwen3SourceModel !== undefined ? qwen3SourceModel : qwenImageSourceModel;+ const qwen3EncoderModel = getMetadataComponent(metadata, 'qwen3_encoder', models);+ const qwenVLEncoderModel = getMetadataComponent(metadata, 'qwen_image_qwen_vl_encoder', models);+ const componentPatch = {+ componentSourceModel: componentSourceModel !== undefined ? componentSourceModel : values.componentSourceModel,+ qwen3EncoderModel: qwen3EncoderModel !== undefined ? qwen3EncoderModel : values.qwen3EncoderModel,+ qwenVLEncoderModel: qwenVLEncoderModel !== undefined ? qwenVLEncoderModel : values.qwenVLEncoderModel,+ };++ if (+ componentPatch.componentSourceModel !== values.componentSourceModel ||+ componentPatch.qwen3EncoderModel !== values.qwen3EncoderModel ||+ componentPatch.qwenVLEncoderModel !== values.qwenVLEncoderModel+ ) {+ values = { ...values, ...componentPatch };+ fields.push('components');+ }+const vae = getMetadataVae(metadata, values.model, vaeModels);if (vae !== undefined) {@@ -366,14 +446,14 @@ export const buildImageRecallSettings = ({}if (kind === 'dimensions') {- const size = getImageSize(image);+ const size = getImageSize(image, values.model);if (size) {values = withDimensions(values, size);fields.push('size');}} else if (kind === 'all' || kind === 'remix') {- const size = getMetadataSize(metadata);+ const size = getMetadataSize(metadata, values.model);if (Object.keys(size).length > 0) {values = withDimensions(values, size);diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.tsindex 69ff886de3..26a17eec95 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts@@ -1,4 +1,4 @@-import type { MainModelConfig, VaeModelConfig } from '@workbench/generation/types';+import type { GenerateModelConfig, VaeModelConfig } from '@workbench/generation/types';import type { ModelConfig } from '@workbench/models/types';import type { WorkbenchAction } from '@workbench/workbenchState';@@ -13,7 +13,7 @@ import {type GalleryBoard,type GalleryImage,} from '@workbench/gallery/api';-import { getDefaultGenerateSettings, isSupportedGenerateModel } from '@workbench/generation/graph';+import { getDefaultGenerateSettings, isSupportedGenerateModel } from '@workbench/generation/baseGenerationPolicies';import { isVaeModelConfig, normalizeGenerateWidgetValues } from '@workbench/generation/settings';import { ensureModelsLoaded, useModelsSnapshot } from '@workbench/models/modelsStore';import { useOpenWorkbenchWidget } from '@workbench/useOpenWorkbenchWidget';@@ -32,7 +32,7 @@ import {/*** Image operations shared by every surface that shows backend images (gallery* grid, preview, image context menus). Each mutation notifies the gallery via- * `touchGalleryRefresh` so any mounted gallery widget refetches.+ * a refresh action so any mounted gallery widget refetches affected backend data.*/export interface ImageActions {copyImage: (image: GalleryImage) => Promise<void>;@@ -92,10 +92,7 @@ export const useImageActions = ({}): ImageActions => {const openWorkbenchWidget = useOpenWorkbenchWidget();const { models } = useModelsSnapshot();- const supportedModels = useMemo<MainModelConfig[]>(- () => models.filter(isSupportedGenerateModel).map((model) => model as MainModelConfig),- [models]- );+ const supportedModels = useMemo<GenerateModelConfig[]>(() => models.filter(isSupportedGenerateModel), [models]);const vaeModels = useMemo<VaeModelConfig[]>(() => models.filter((model: ModelConfig) => isVaeModelConfig(model)).map((model) => model as VaeModelConfig),[models]@@ -124,6 +121,7 @@ export const useImageActions = ({const recordInfo = (title: string, message?: string) =>dispatch({ kind: 'info', message, title, type: 'recordNotice' });const refreshGallery = () => dispatch({ type: 'touchGalleryRefresh' });+ const refreshGalleryImages = () => dispatch({ type: 'touchGalleryImagesRefresh' });const getBoardName = (boardId: string) => boards.find((board) => board.id === boardId)?.name ?? 'Uncategorized';const imageMetadataRequests = new Map<string, Promise<unknown>>();const loadImageMetadata = (imageName: string): Promise<unknown> => {@@ -209,6 +207,7 @@ export const useImageActions = ({currentValues: currentGenerateValues,image,metadata,+ models,supportedModels,vaeModels,});@@ -255,6 +254,7 @@ export const useImageActions = ({image,kind,metadata,+ models,supportedModels,vaeModels,});@@ -278,7 +278,7 @@ export const useImageActions = ({try {await (starred ? starGalleryImages : unstarGalleryImages)(imageNames);- refreshGallery();+ refreshGalleryImages();} catch (error: unknown) {onStarredChange?.(imageNames, !starred);recordError(error);@@ -289,6 +289,7 @@ export const useImageActions = ({boards,currentGenerateValues,dispatch,+ models,onImagesDeleted,onStarredChange,openWorkbenchWidget,diff --git a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryBoardSelect.tsx b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryBoardSelect.tsxindex b2355c7435..626202144e 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryBoardSelect.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryBoardSelect.tsx@@ -113,7 +113,7 @@ export const GalleryBoardSelect = () => {}}><Menu.Trigger asChild>- <Button justifyContent="space-between" minW="0" size="sm" variant="outline" w="full" px="1">+ <Button minW="0" size="sm" variant="outline" w="full" px="1">{selectedBoard ? (<BoardOptionContentbadge={selectedBoard.id === gallery.projectBoardId ? 'Project' : undefined}@@ -121,7 +121,9 @@ export const GalleryBoardSelect = () => {isSelected={false}/>) : (- <Text fontSize="xs">Loading board...</Text>+ <Text fontSize="xs" me="auto">+ Loading board...+ </Text>)}<Icon as={ChevronDownIcon} boxSize="3" flexShrink={0} /></Button>@@ -400,7 +402,7 @@ const BoardOptionContent = ({return (<HStack gap="2" minW="0" w="full"><BoardCover board={board} />- <Stack flex="1" gap="1" minW="0">+ <Stack gap="1" minW="0"><Text fontSize="xs" fontWeight={isSelected ? '700' : '500'} minW="0" lineHeight={1} truncate>{board.name}</Text>@@ -410,14 +412,16 @@ const BoardOptionContent = ({</Text>) : null}</Stack>- {badge && (- <Badge colorPalette={badge === 'Project' ? 'blue' : 'gray'} flexShrink={0} size="xs" variant="subtle">- {badge}+ <Flex ms="auto">+ {badge && (+ <Badge colorPalette={badge === 'Project' ? 'blue' : 'gray'} flexShrink={0} size="xs" variant="subtle">+ {badge}+ </Badge>+ )}+ <Badge flexShrink={0} size="xs" variant={isSelected ? 'solid' : 'subtle'}>+ {counts.imageCount} | {counts.assetCount}</Badge>- )}- <Badge flexShrink={0} size="xs" variant={isSelected ? 'solid' : 'subtle'}>- {counts.imageCount} | {counts.assetCount}- </Badge>+ </Flex></HStack>);};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryImageGrid.tsx b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryImageGrid.tsxindex 3bb6c22086..b76038db79 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryImageGrid.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryImageGrid.tsx@@ -412,7 +412,7 @@ const GalleryQueuePlaceholderCell = ({as="button"aria-label="Show in-progress diffusion in Preview"aspectRatio={1}- bg="bg.emphasized"+ bg="bg"borderColor={isActive ? 'accent.solid' : 'border.subtle'}borderWidth="1px"cursor="pointer"@@ -498,7 +498,7 @@ const GalleryThumbnail = ({return (<BoxaspectRatio={1}- bg="bg.emphasized"+ bg="bg"borderWidth="2px"borderColor={isSelected || isCompared ? 'accent.solid' : 'border.subtle'}boxShadow={isCompared ? 'inset 0 0 0 1px {colors.accent.solid}' : undefined}diff --git a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryToolbar.tsx b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryToolbar.tsxindex 37b4cec4f7..f12d182425 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryToolbar.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryToolbar.tsx@@ -50,9 +50,6 @@ export const GalleryToolbar = ({ layout }: { layout: 'stacked' | 'wide' }) => {const toolbarActions = (<HStack gap="2">- <Text color="fg.subtle" fontSize="2xs">- {gallery.images.length} loaded- </Text><GalleryUploadButton /><GallerySettingsMenu /></HStack>@@ -60,6 +57,17 @@ export const GalleryToolbar = ({ layout }: { layout: 'stacked' | 'wide' }) => {const searchClearButton = gallery.searchTerm ? (<CloseButton size="2xs" aria-label="Clear search" onClick={() => actions.setSearchTerm('')} me="-2" />) : null;+ const searchInput = (+ <InputGroup startElement={<Icon as={SearchIcon} size="sm" />} endElement={searchClearButton}>+ <Input+ aria-label="Search gallery images"+ placeholder="Search images"+ size="xs"+ value={gallery.searchTerm}+ onChange={(event) => actions.setSearchTerm(event.currentTarget.value)}+ />+ </InputGroup>+ );return (<Stack gap="2">@@ -70,6 +78,9 @@ export const GalleryToolbar = ({ layout }: { layout: 'stacked' | 'wide' }) => {</Box>{viewTabs}<Spacer />+ <Box flex="1" maxW="20rem" minW="12rem">+ {searchInput}+ </Box>{toolbarActions}</HStack>) : (@@ -81,15 +92,7 @@ export const GalleryToolbar = ({ layout }: { layout: 'stacked' | 'wide' }) => {</HStack></>)}- <InputGroup startElement={<Icon as={SearchIcon} size="sm" />} endElement={searchClearButton}>- <Input- aria-label="Search gallery images"- placeholder="Search images"- size="xs"- value={gallery.searchTerm}- onChange={(event) => actions.setSearchTerm(event.currentTarget.value)}- />- </InputGroup>+ {!isWide && searchInput}</Stack>);};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryWidgetView.tsxindex 4cc8a13df9..aa4eea48c3 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/gallery/GalleryWidgetView.tsx@@ -11,6 +11,7 @@ import { GalleryPanelContent } from './GalleryPanelContent';import {getGalleryPage,getGalleryProjectBoardId,+ getGalleryImagesRefreshToken,getGalleryRecentImagesKey,getGalleryRefreshToken,getGallerySearchTerm,@@ -31,12 +32,14 @@ export const GalleryWidgetView = ({ presentation, region }: WidgetViewProps) =>const searchTerm = getGallerySearchTerm(galleryValues);const recentImagesKey = getGalleryRecentImagesKey(galleryValues);const refreshToken = getGalleryRefreshToken(galleryValues);+ const imageRefreshToken = getGalleryImagesRefreshToken(galleryValues);const page = getGalleryPage(galleryValues);const knownTotalImages = getGalleryTotalImages(galleryValues);const settings = getGallerySettings(galleryValues);const onError = useCallback((message: string) => dispatch({ message, type: 'recordError' }), [dispatch]);const data = useGalleryData({galleryView,+ imageRefreshToken,onError,page,recentImagesKey,@@ -123,7 +126,7 @@ export const GalleryWidgetView = ({ presentation, region }: WidgetViewProps) =>// render page navigation without its own fetch, and clamp the page when the// query shrinks (e.g. after deletions).useEffect(() => {- if (total !== null && total !== knownTotalImages) {+ if (typeof total === 'number' && Number.isFinite(total) && total !== knownTotalImages) {dispatch({ totalImages: total, type: 'setGalleryPageInfo' });}}, [dispatch, knownTotalImages, total]);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.test.tsindex e0f47ab729..c5f6c74fee 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.test.ts@@ -5,6 +5,7 @@ import { describe, expect, it } from 'vitest';import {getBoardCounts,+ getGalleryImagesRefreshToken,getGalleryQueuePlaceholders,getGallerySelectedBoardId,getGalleryStateView,@@ -102,6 +103,13 @@ describe('gallery state view', () => {});});+ it('falls back to the full gallery refresh token when image refresh token is absent', () => {+ expect(getGalleryImagesRefreshToken({ galleryRefreshToken: 'full-refresh' })).toBe('full-refresh');+ expect(+ getGalleryImagesRefreshToken({ galleryImagesRefreshToken: 'image-refresh', galleryRefreshToken: 'full-refresh' })+ ).toBe('image-refresh');+ });+it('derives the multi-selection from persisted values with a single-selection fallback', () => {expect(getGalleryStateView({ selectedImageNames: ['a.png', 'b.png', 7] }, boards, [], false).selectedImageNames@@ -111,6 +119,19 @@ describe('gallery state view', () => {]);});+ it('restores the selection set from a visible primary image after tab switches clear it', () => {+ const image = createImage('selected.png');+ const gallery = getGalleryStateView(+ { selectedImageName: image.imageName, selectedImageNames: [] },+ boards,+ [{ ...image, boardId: 'none', imageCategory: 'general', starred: false }],+ false+ );++ expect(gallery.selectedImageName).toBe(image.imageName);+ expect(gallery.selectedImageNames).toEqual([image.imageName]);+ });+it('creates placeholders for in-flight gallery queue items on the viewed board', () => {const queueItems = [createQueueItem({ batchCount: 2, boardId: 'board-1', status: 'pending' }),diff --git a/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.ts b/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.tsindex 380647475c..f5bdb63ac6 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/gallery/galleryStateView.ts@@ -77,6 +77,11 @@ export const getGalleryTotalImages = (values: Record<string, unknown>): number |export const getGalleryRefreshToken = (values: Record<string, unknown>): string =>typeof values.galleryRefreshToken === 'string' ? values.galleryRefreshToken : '';+export const getGalleryImagesRefreshToken = (values: Record<string, unknown>): string =>+ typeof values.galleryImagesRefreshToken === 'string'+ ? values.galleryImagesRefreshToken+ : getGalleryRefreshToken(values);+export const getGalleryProjectBoardId = (values: Record<string, unknown>): string | null =>typeof values.projectBoardId === 'string' ? values.projectBoardId : null;@@ -187,6 +192,10 @@ export const getGalleryStateView = (: [];const images = backendImages ?? (isLoading ? [] : localImages);const selectedImageName = typeof values.selectedImageName === 'string' ? values.selectedImageName : null;+ const visibleSelectedImageName = images.some((image) => image.imageName === selectedImageName)+ ? selectedImageName+ : null;+ const selectedImageNames = getGallerySelectedImageNames(values);const galleryView = getGalleryView(values);const settings = getGallerySettings(values);const searchTerm = getGallerySearchTerm(values);@@ -204,8 +213,11 @@ export const getGalleryStateView = (projectBoardId: getGalleryProjectBoardId(values),searchTerm,selectedBoardId,- selectedImageName: images.some((image) => image.imageName === selectedImageName) ? selectedImageName : null,- selectedImageNames: getGallerySelectedImageNames(values),+ selectedImageName: visibleSelectedImageName,+ selectedImageNames:+ visibleSelectedImageName && !selectedImageNames.includes(visibleSelectedImageName)+ ? [visibleSelectedImageName, ...selectedImageNames]+ : selectedImageNames,settings,};};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/gallery/useGalleryData.ts b/invokeai/frontend/webv2/src/workbench/widgets/gallery/useGalleryData.tsindex e30f12b559..fc1449e639 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/gallery/useGalleryData.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/gallery/useGalleryData.ts@@ -92,6 +92,7 @@ export interface GalleryData {export const useGalleryData = ({galleryView,+ imageRefreshToken,onError,page,recentImagesKey,@@ -101,6 +102,7 @@ export const useGalleryData = ({settings,}: {galleryView: GalleryView;+ imageRefreshToken: string;onError: (message: string) => void;page: number;recentImagesKey: string;@@ -124,7 +126,6 @@ export const useGalleryData = ({boardOrderDir,String(showDateBoards),refreshToken,- recentImagesKey,].join('\0');const cachedBoardsEntry = boardsCache.get(boardsKey);const isBoardsCacheFresh = isCacheEntryFresh(cachedBoardsEntry);@@ -144,7 +145,7 @@ export const useGalleryData = ({const pageCount = infiniteWindow.baseKey === baseKey ? infiniteWindow.pageCount : cachedPageCount;const offset = isPaginated ? page * GALLERY_PAGE_SIZE : 0;const limit = isPaginated ? GALLERY_PAGE_SIZE : pageCount * GALLERY_PAGE_SIZE;- const fetchKey = [baseKey, String(offset), String(limit), refreshToken, recentImagesKey].join('\0');+ const fetchKey = [baseKey, String(offset), String(limit), imageRefreshToken, recentImagesKey].join('\0');const exactCachedImageResultEntry = imageResultByFetchKeyCache.get(fetchKey);const baseCachedImageResultEntry = imageResultByBaseKeyCache.get(baseKey);const cachedImageResultEntry = exactCachedImageResultEntry ?? baseCachedImageResultEntry;diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsxindex 415cd63ec8..02eae1def8 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx@@ -14,8 +14,8 @@ import { getGallerySettings } from '@workbench/gallery/settings';import { ImageContextMenu, useImageActions, type ImageContextMenuTarget } from '@workbench/image-actions';import {getGalleryCompareImage,+ getGalleryImagesRefreshToken,getGalleryRecentImagesKey,- getGalleryRefreshToken,} from '@workbench/widgets/gallery/galleryStateView';import { useActiveProjectSelector, useWorkbenchDispatch } from '@workbench/WorkbenchContext';import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';@@ -113,7 +113,7 @@ export const PreviewWidgetView = ({ region }: WidgetViewProps) => {const hasSelectedImage = selectedImage !== null;const isBackendImage = selectedImage ? shouldLoadBackendBoard(selectedImage) : false;const { imageOrderDir, starredFirst } = getGallerySettings(galleryValues);- const refreshToken = getGalleryRefreshToken(galleryValues);+ const imageRefreshToken = getGalleryImagesRefreshToken(galleryValues);const recentImagesKey = getGalleryRecentImagesKey(galleryValues);const [boards, setBoards] = useState<GalleryBoard[]>(fallbackBoards);const [boardImages, setBoardImages] = useState<PreviewImage[]>(localImages);@@ -191,10 +191,10 @@ export const PreviewWidgetView = ({ region }: WidgetViewProps) => {hasSelectedImage,imageBoardId,imageOrderDir,+ imageRefreshToken,isBackendImage,localImages,recentImagesKey,- refreshToken,selectedGalleryView,starredFirst,]);