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): add mixed gallery data layer
joshistoast056f9ccd8e52
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.tsindex 0920f26bc3..60ccdeb790 100644--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts@@ -1,3 +1,4 @@+import { galleryItems } from '@features/gallery';import { accountLifecycle } from '@platform/state/accountLifecycle';import { beforeEach, describe, expect, it, vi } from 'vitest';@@ -20,11 +21,14 @@ import {downloadGalleryArchive,getGalleryImageByName,getGalleryImagesByNames,+ getGalleryVideoMetadata,+ getGalleryVideoWorkflow,imageMakeCanvasAssetChanges,imageMakeDurableChanges,imageSaveToGalleryChanges,listGalleryBoards,- listGalleryImages,+ listGalleryItems,+ listPaletteImages,} from './backend';describe('downloadGalleryArchive', () => {@@ -148,14 +152,14 @@ describe('getGalleryImagesByNames', () => {});});-describe('listGalleryImages created-at range', () => {+describe('listPaletteImages created-at range', () => {beforeEach(() => {mocks.apiFetchJson.mockReset();mocks.apiFetchJson.mockResolvedValue({ items: [], limit: 20, offset: 0, total: 0 });});it('sends created_from/created_to as query params', async () => {- await listGalleryImages({+ await listPaletteImages({boardId: 'board-1',createdFrom: '2026-07-01',createdTo: '2026-07-15',@@ -172,7 +176,7 @@ describe('listGalleryImages created-at range', () => {it('sends the explicit all-readable scope and forwards cancellation', async () => {const controller = new AbortController();- await listGalleryImages({+ await listPaletteImages({boardId: 'all',galleryView: 'images',searchTerm: 'sunset',@@ -186,7 +190,7 @@ describe('listGalleryImages created-at range', () => {});it('omits the range params when no range is given', async () => {- await listGalleryImages({ boardId: 'board-1', galleryView: 'images', searchTerm: 'sunset' });+ await listPaletteImages({ boardId: 'board-1', galleryView: 'images', searchTerm: 'sunset' });const url = mocks.apiFetchJson.mock.calls[0]?.[0] as string;const params = new URLSearchParams(url.split('?')[1]);@@ -196,7 +200,7 @@ describe('listGalleryImages created-at range', () => {it('short-circuits a date board that falls outside the range without a request', async () => {await expect(- listGalleryImages({+ listPaletteImages({boardId: 'by_date:2026-07-18',createdFrom: '2026-07-01',createdTo: '2026-07-15',@@ -211,7 +215,7 @@ describe('listGalleryImages created-at range', () => {mocks.apiFetchJson.mockResolvedValue({ image_names: [], total_count: 0 });await expect(- listGalleryImages({+ listPaletteImages({boardId: 'by_date:2026-07-10',createdFrom: '2026-07-01',createdTo: '2026-07-15',@@ -223,6 +227,263 @@ describe('listGalleryImages created-at range', () => {});});+describe('listGalleryItems', () => {+ beforeEach(() => {+ mocks.apiFetchJson.mockReset();+ });++ it('maps a mixed page by kind and normalizes transport-only fields', async () => {+ mocks.apiFetchJson.mockResolvedValue({+ items: [+ {+ board_id: null,+ category: 'general',+ created_at: '2026-07-20T10:00:00.000Z',+ duration: 8.5,+ full_url: '/images/still.png',+ height: 512,+ is_intermediate: false,+ kind: 'image',+ name: 'still.png',+ starred: true,+ thumbnail_url: '/thumbnails/still.webp',+ width: 768,+ },+ {+ board_id: 'board-1',+ category: 'general',+ created_at: '2026-07-20T09:00:00.000Z',+ duration: 3.25,+ fps: null,+ full_url: '/videos/clip.mp4',+ height: 720,+ is_intermediate: true,+ kind: 'video',+ name: 'clip.mp4',+ starred: false,+ thumbnail_url: '/thumbnails/clip.webp',+ width: 1280,+ },+ ],+ limit: 20,+ offset: 0,+ total: 2,+ });++ await expect(listGalleryItems({ boardId: 'board-1', galleryView: 'images', searchTerm: '' })).resolves.toEqual({+ items: [+ {+ boardId: 'none',+ category: 'general',+ createdAt: '2026-07-20T10:00:00.000Z',+ fullUrl: 'https://api.test/images/still.png',+ height: 512,+ isIntermediate: false,+ kind: 'image',+ name: 'still.png',+ starred: true,+ thumbnailUrl: 'https://api.test/thumbnails/still.webp',+ width: 768,+ },+ {+ boardId: 'board-1',+ category: 'general',+ createdAt: '2026-07-20T09:00:00.000Z',+ durationSeconds: 3.25,+ fullUrl: 'https://api.test/videos/clip.mp4',+ height: 720,+ isIntermediate: true,+ kind: 'video',+ name: 'clip.mp4',+ starred: false,+ thumbnailUrl: 'https://api.test/thumbnails/clip.webp',+ width: 1280,+ },+ ],+ total: 2,+ });+ });++ it.each([undefined, null, Number.NaN, Number.POSITIVE_INFINITY])(+ 'rejects a video whose duration is not finite: %s',+ async (duration) => {+ mocks.apiFetchJson.mockResolvedValue({+ items: [+ {+ board_id: null,+ category: 'general',+ created_at: '2026-07-20T09:00:00.000Z',+ duration,+ full_url: '/videos/broken.mp4',+ height: 720,+ is_intermediate: false,+ kind: 'video',+ name: 'broken.mp4',+ starred: false,+ thumbnail_url: '/thumbnails/broken.webp',+ width: 1280,+ },+ ],+ limit: 20,+ offset: 0,+ total: 1,+ });++ await expect(listGalleryItems({ boardId: 'none', galleryView: 'images', searchTerm: '' })).rejects.toThrow(+ 'finite duration'+ );+ }+ );++ it('forwards gallery filters and pagination to the polymorphic endpoint', async () => {+ const controller = new AbortController();+ mocks.apiFetchJson.mockResolvedValue({ items: [], limit: 17, offset: 34, total: 0 });++ await listGalleryItems({+ boardId: 'board-1',+ createdFrom: '2026-07-01',+ createdTo: '2026-07-15',+ galleryView: 'images',+ isIntermediate: true,+ limit: 17,+ offset: 34,+ orderDir: 'ASC',+ searchTerm: ' summer clip ',+ signal: controller.signal,+ starredFirst: true,+ });++ const [url, init] = mocks.apiFetchJson.mock.calls[0] as [string, RequestInit];+ const params = new URLSearchParams(url.split('?')[1]);++ expect(url.split('?')[0]).toBe('/api/v1/gallery/items/');+ expect(params.get('board_id')).toBe('board-1');+ expect(params.getAll('categories')).toEqual(['general']);+ expect(params.get('created_from')).toBe('2026-07-01');+ expect(params.get('created_to')).toBe('2026-07-15');+ expect(params.get('is_intermediate')).toBe('true');+ expect(params.get('limit')).toBe('17');+ expect(params.get('offset')).toBe('34');+ expect(params.get('order_dir')).toBe('ASC');+ expect(params.get('starred_first')).toBe('true');+ expect(params.get('search_term')).toBe('summer clip');+ expect(init.signal).toBe(controller.signal);+ });++ it('uses asset categories so general-category videos stay out of Assets', async () => {+ mocks.apiFetchJson.mockResolvedValue({ items: [], limit: 100, offset: 0, total: 0 });++ await listGalleryItems({ boardId: 'board-1', galleryView: 'assets', searchTerm: '' });++ const url = mocks.apiFetchJson.mock.calls[0]?.[0] as string;+ const categories = new URLSearchParams(url.split('?')[1]).getAll('categories');++ expect(categories).toEqual(['control', 'mask', 'user']);+ expect(categories).not.toContain('general');+ });+});++describe('palette image search', () => {+ beforeEach(() => {+ mocks.apiFetchJson.mockReset();+ mocks.apiFetchJson.mockResolvedValue({ items: [], limit: 20, offset: 0, total: 0 });+ });++ it('keeps all-readable palette searches on the image-only endpoint', async () => {+ await listPaletteImages({ boardId: 'all', galleryView: 'images', limit: 20, searchTerm: ' portrait ' });++ const url = mocks.apiFetchJson.mock.calls[0]?.[0] as string;+ const params = new URLSearchParams(url.split('?')[1]);++ expect(url.split('?')[0]).toBe('/api/v1/images/');+ expect(params.get('board_id')).toBe('all');+ expect(params.get('search_term')).toBe('portrait');+ });+});++describe('mixed gallery item details', () => {+ beforeEach(() => {+ mocks.apiFetchJson.mockReset();+ });++ it('resolves an image ref through the strict image DTO mapper', async () => {+ mocks.apiFetchJson.mockResolvedValue({+ board_id: null,+ created_at: '2026-07-20T10:00:00.000Z',+ height: 512,+ image_category: 'general',+ image_name: 'folder/still.png',+ image_url: '/images/still.png',+ is_intermediate: false,+ starred: false,+ thumbnail_url: '/thumbnails/still.webp',+ width: 768,+ });++ await expect(galleryItems.resolve({ kind: 'image', name: 'folder/still.png' })).resolves.toMatchObject({+ kind: 'image',+ name: 'folder/still.png',+ });+ expect(mocks.apiFetchJson).toHaveBeenCalledWith('/api/v1/images/i/folder%2Fstill.png', { signal: undefined });+ });++ it('resolves a video ref and omits absent fps', async () => {+ mocks.apiFetchJson.mockResolvedValue({+ board_id: null,+ created_at: '2026-07-20T10:00:00.000Z',+ duration: 4.5,+ fps: null,+ height: 720,+ is_intermediate: false,+ starred: true,+ thumbnail_url: '/thumbnails/clip.webp',+ video_category: 'general',+ video_name: 'folder/clip.mp4',+ video_url: '/videos/clip.mp4',+ width: 1280,+ });++ const item = await galleryItems.resolve({ kind: 'video', name: 'folder/clip.mp4' });++ expect(item).toEqual({+ boardId: 'none',+ category: 'general',+ createdAt: '2026-07-20T10:00:00.000Z',+ durationSeconds: 4.5,+ fullUrl: 'https://api.test/videos/clip.mp4',+ height: 720,+ isIntermediate: false,+ kind: 'video',+ name: 'folder/clip.mp4',+ starred: true,+ thumbnailUrl: 'https://api.test/thumbnails/clip.webp',+ width: 1280,+ });+ expect(mocks.apiFetchJson).toHaveBeenCalledWith('/api/v1/videos/i/folder%2Fclip.mp4', { signal: undefined });+ });++ it('fetches focused video metadata and workflow details', async () => {+ const controller = new AbortController();+ mocks.apiFetchJson+ .mockResolvedValueOnce({ positive_prompt: 'moving portrait' })+ .mockResolvedValueOnce({ graph: '{"nodes":[]}', workflow: null });++ await expect(getGalleryVideoMetadata('folder/clip.mp4', controller.signal)).resolves.toEqual({+ positive_prompt: 'moving portrait',+ });+ await expect(getGalleryVideoWorkflow('folder/clip.mp4', controller.signal)).resolves.toEqual({+ graph: '{"nodes":[]}',+ workflow: null,+ });+ expect(mocks.apiFetchJson).toHaveBeenNthCalledWith(1, '/api/v1/videos/i/folder%2Fclip.mp4/metadata', {+ signal: controller.signal,+ });+ expect(mocks.apiFetchJson).toHaveBeenNthCalledWith(2, '/api/v1/videos/i/folder%2Fclip.mp4/workflow', {+ signal: controller.signal,+ });+ });+});+describe('imageSaveToGalleryChanges', () => {it('promotes an intermediate candidate to a durable, gallery-visible image', () => {// The backend `ImageRecordChanges` body: clear `is_intermediate` (stop GC)@@ -266,7 +527,7 @@ describe('gallery category queries', () => {});const categoriesFor = async (galleryView: 'images' | 'assets'): Promise<string[]> => {- await listGalleryImages({ boardId: 'board-1', galleryView, searchTerm: '' });+ await listPaletteImages({ boardId: 'board-1', galleryView, searchTerm: '' });const url = mocks.apiFetchJson.mock.calls[0]?.[0] as string;return new URLSearchParams(url.split('?')[1]).getAll('categories');diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.tsindex 0ba9629e6d..efac90cbe1 100644--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts@@ -1,3 +1,11 @@+import type {+ GalleryImageItem,+ GalleryItem,+ GalleryItemCategory,+ GalleryItemRef,+ GalleryItemsPage,+ GalleryVideoItem,+} from '@features/gallery/core/items';import type {GalleryBoard,GalleryBoardOrderBy,@@ -57,6 +65,37 @@ interface BackendImageDTO {board_id?: string | null;}+export interface BackendGalleryItemDTO {+ board_id?: string | null;+ category: GalleryItemCategory;+ created_at: string;+ duration?: number | null;+ fps?: number | null;+ full_url: string;+ height: number;+ is_intermediate: boolean;+ kind: 'image' | 'video';+ name: string;+ starred: boolean;+ thumbnail_url: string;+ width: number;+}++interface BackendVideoDTO {+ board_id?: string | null;+ created_at: string;+ duration: number;+ fps?: number | null;+ height: number;+ is_intermediate: boolean;+ starred: boolean;+ thumbnail_url: string;+ video_category: GalleryItemCategory;+ video_name: string;+ video_url: string;+ width: number;+}+interface ListImagesResponse {items: BackendImageDTO[];limit: number;@@ -175,6 +214,77 @@ const mapImage = (image: BackendImageDTO): GalleryImage => ({width: image.width,});+const mapGalleryItemBase = (+ item: BackendGalleryItemDTO+): Omit<GalleryItem, 'durationSeconds' | 'fps' | 'kind' | 'sourceQueueItemId'> => ({+ boardId: item.board_id ?? 'none',+ category: item.category,+ createdAt: item.created_at,+ fullUrl: absolutizeApiUrl(item.full_url),+ height: item.height,+ isIntermediate: item.is_intermediate,+ name: item.name,+ starred: item.starred,+ thumbnailUrl: absolutizeApiUrl(item.thumbnail_url),+ width: item.width,+});++const mapGalleryItem = (item: BackendGalleryItemDTO): GalleryItem => {+ const base = mapGalleryItemBase(item);++ if (item.kind === 'image') {+ return { ...base, kind: 'image' };+ }++ if (typeof item.duration !== 'number' || !Number.isFinite(item.duration)) {+ throw new TypeError(`Gallery video "${item.name}" must have a finite duration.`);+ }++ return {+ ...base,+ durationSeconds: item.duration,+ ...(item.fps === null || item.fps === undefined ? {} : { fps: item.fps }),+ kind: 'video',+ };+};++const mapBackendImageToGalleryItem = (image: BackendImageDTO): GalleryImageItem => ({+ boardId: image.board_id ?? 'none',+ category: image.image_category,+ createdAt: image.created_at,+ fullUrl: absolutizeApiUrl(image.image_url),+ height: image.height,+ isIntermediate: image.is_intermediate,+ kind: 'image',+ name: image.image_name,+ sourceQueueItemId: 'backend-gallery',+ starred: image.starred ?? false,+ thumbnailUrl: absolutizeApiUrl(image.thumbnail_url),+ width: image.width,+});++const mapVideo = (video: BackendVideoDTO): GalleryVideoItem => {+ if (!Number.isFinite(video.duration)) {+ throw new TypeError(`Gallery video "${video.video_name}" must have a finite duration.`);+ }++ return {+ boardId: video.board_id ?? 'none',+ category: video.video_category,+ createdAt: video.created_at,+ durationSeconds: video.duration,+ ...(video.fps === null || video.fps === undefined ? {} : { fps: video.fps }),+ fullUrl: absolutizeApiUrl(video.video_url),+ height: video.height,+ isIntermediate: video.is_intermediate,+ kind: 'video',+ name: video.video_name,+ starred: video.starred,+ thumbnailUrl: absolutizeApiUrl(video.thumbnail_url),+ width: video.width,+ };+};+const normalizeTotal = (value: unknown, fallback: number): number =>typeof value === 'number' && Number.isFinite(value) ? Math.max(0, value) : Math.max(0, fallback);@@ -282,6 +392,39 @@ export const getGalleryImageByName = async (imageName: string, signal?: AbortSigreturn mapImage(body);};+export const getGalleryVideoByName = async (videoName: string, signal?: AbortSignal): Promise<GalleryVideoItem> => {+ const body = await apiFetchJson<BackendVideoDTO>(`/api/v1/videos/i/${encodeURIComponent(videoName)}`, { signal });++ return mapVideo(body);+};++export const getGalleryItemByRef = async (ref: GalleryItemRef, signal?: AbortSignal): Promise<GalleryItem> => {+ if (ref.kind === 'image') {+ const body = await apiFetchJson<BackendImageDTO>(`/api/v1/images/i/${encodeURIComponent(ref.name)}`, { signal });++ return mapBackendImageToGalleryItem(body);+ }++ return getGalleryVideoByName(ref.name, signal);+};++export const getGalleryVideoMetadata = async (+ videoName: string,+ signal?: AbortSignal+): Promise<Record<string, unknown> | null> => {+ const body = await apiFetchJson<unknown>(`/api/v1/videos/i/${encodeURIComponent(videoName)}/metadata`, { signal });++ return body && typeof body === 'object' && !Array.isArray(body) ? (body as Record<string, unknown>) : null;+};++export interface GalleryVideoWorkflow {+ graph: string | null;+ workflow: string | null;+}++export const getGalleryVideoWorkflow = (videoName: string, signal?: AbortSignal): Promise<GalleryVideoWorkflow> =>+ apiFetchJson<GalleryVideoWorkflow>(`/api/v1/videos/i/${encodeURIComponent(videoName)}/workflow`, { signal });+export interface GalleryDateBoardImageNames {imageNames: string[];total: number;@@ -352,18 +495,7 @@ export const hydrateGalleryDateBoardImagePage = async ({total,});-export const listGalleryImages = async ({- boardId,- createdFrom,- createdTo,- galleryView,- limit = 100,- offset = 0,- orderDir = 'DESC',- searchTerm,- signal,- starredFirst = false,-}: {+interface GalleryListRequest {boardId: string;createdFrom?: string;createdTo?: string;@@ -374,7 +506,62 @@ export const listGalleryImages = async ({searchTerm: string;signal?: AbortSignal;starredFirst?: boolean;-}): Promise<GalleryImagesPage> => {+}++interface GalleryItemsRequest extends GalleryListRequest {+ isIntermediate?: boolean;+}++export const listGalleryItems = async ({+ boardId,+ createdFrom,+ createdTo,+ galleryView,+ isIntermediate = false,+ limit = 100,+ offset = 0,+ orderDir = 'DESC',+ searchTerm,+ signal,+ starredFirst = false,+}: GalleryItemsRequest): Promise<GalleryItemsPage> => {+ const query = toSearchParams({+ board_id: boardId,+ categories: galleryView === 'assets' ? assetCategories : imageCategories,+ created_from: createdFrom,+ created_to: createdTo,+ is_intermediate: isIntermediate,+ limit,+ offset,+ order_dir: orderDir,+ search_term: searchTerm.trim() || undefined,+ starred_first: starredFirst,+ });+ const body = await apiFetchJson<{+ items: BackendGalleryItemDTO[];+ limit: number;+ offset: number;+ total: number;+ }>(`/api/v1/gallery/items/?${query}`, { signal });++ return {+ items: body.items.map(mapGalleryItem),+ total: normalizeTotal(body.total, offset + body.items.length),+ };+};++export const listPaletteImages = async ({+ boardId,+ createdFrom,+ createdTo,+ galleryView,+ limit = 100,+ offset = 0,+ orderDir = 'DESC',+ searchTerm,+ signal,+ starredFirst = false,+}: GalleryListRequest): Promise<GalleryImagesPage> => {if (isDateBoardId(boardId)) {const names = await listGalleryDateBoardImageNames({boardId,@@ -414,6 +601,13 @@ export const listGalleryImages = async ({};};+/**+ * TODO(Task 4): Remove this image-page compatibility alias when gallery query+ * consumers switch to `listGalleryItems`. Palette search must call+ * `listPaletteImages` directly and remain image-only.+ */+export const listGalleryImages = listPaletteImages;+/*** The `ImageRecordChanges` body that promotes a staged canvas candidate (an* intermediate image) into a durable, gallery-visible image: clearingdiff --git a/invokeai/frontend/webv2/src/features/gallery/index.ts b/invokeai/frontend/webv2/src/features/gallery/index.tsindex e0ec20066d..76acd62150 100644--- a/invokeai/frontend/webv2/src/features/gallery/index.ts+++ b/invokeai/frontend/webv2/src/features/gallery/index.ts@@ -35,6 +35,9 @@ import {getGalleryImageByName,getGalleryImageMetadata,getGalleryImagesByNames,+ getGalleryItemByRef,+ getGalleryVideoMetadata,+ getGalleryVideoWorkflow,isDateBoardId,listGalleryBoards,makeImageCanvasAsset,@@ -53,6 +56,17 @@ export const galleryImages = {resolveMany: getGalleryImagesByNames,} as const;+/** Resolve either media kind while keeping the legacy image port strictly image-only. */+export const galleryItems = {+ resolve: getGalleryItemByRef,+} as const;++/** Focused read-only details needed by mixed-media preview surfaces. */+export const galleryVideos = {+ metadata: getGalleryVideoMetadata,+ workflow: getGalleryVideoWorkflow,+} as const;+/** Import/export intents shared by image-producing and image-consuming features. */export const galleryTransfers = {downloadArchive: downloadGalleryArchive,diff --git a/invokeai/frontend/webv2/src/features/gallery/paletteSearch.ts b/invokeai/frontend/webv2/src/features/gallery/paletteSearch.tsindex b1bace27fb..a530c22241 100644--- a/invokeai/frontend/webv2/src/features/gallery/paletteSearch.ts+++ b/invokeai/frontend/webv2/src/features/gallery/paletteSearch.ts@@ -1,2 +1,2 @@/** Cancellable gallery reads used by deferred cross-feature search surfaces. */-export { ALL_READABLE_BOARDS_ID, listGalleryBoards, listGalleryImages } from './data/backend';+export { ALL_READABLE_BOARDS_ID, listGalleryBoards, listPaletteImages } from './data/backend';diff --git a/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.ts b/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.tsindex d5d69d85d2..d9f8fd2444 100644--- a/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.ts+++ b/invokeai/frontend/webv2/src/workbench/palette/paletteProviders.ts@@ -5,7 +5,7 @@ import type { QueueReadModel } from '@features/queue/contracts';import type { PromptHistoryItem } from '@workbench/projectContracts';import type { TFunction } from 'i18next';-import { ALL_READABLE_BOARDS_ID, listGalleryImages } from '@features/gallery/paletteSearch';+import { ALL_READABLE_BOARDS_ID, listPaletteImages } from '@features/gallery/paletteSearch';import { galleryBoardsOptions } from '@features/gallery/queries';import { focusPositivePrompt } from '@features/generation/react';import { isSupportedGenerateModel } from '@features/generation/settings';@@ -308,7 +308,7 @@ export const createImagesProvider = ({// Search the explicit all-readable scope. The endpoint excludes archived// and inaccessible boards; the active board list supplies display labels.const [page, boards] = await Promise.all([- listGalleryImages({+ listPaletteImages({boardId: ALL_READABLE_BOARDS_ID,createdFrom: query.range?.from,createdTo: query.range?.to,