/** * Lightweight IndexedDB persistence layer for Image Generation Gallery. * Stores lightweight metadata indexes; image binaries remain managed by DSH Attachment service. * Supports tombstones to ensure deleted items are never resurrected when revisiting conversations. */ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'; import type { ImageProvider, StudioWatermark } from '../shared.js'; export interface GalleryItem { id: string; attachment: ImageAttachmentRef; prompt: string; /** Generation provider, or 'import' for user-uploaded images. */ provider: ImageProvider | 'import'; channel?: string | undefined; model: string; createdAt: number; aspectRatio?: string | undefined; imageSize?: string | undefined; resolution?: string | undefined; generationQuality?: string | undefined; watermark?: StudioWatermark | undefined; output?: string | undefined; /** Workflow seed reported by the ComfyUI provider. Optional so records written by older versions stay readable; the object store is schemaless, so no IndexedDB version bump is needed. */ seed?: number | undefined; /** ComfyUI timing split, stored for the details panel. */ queueMs?: number | undefined; execMs?: number | undefined; totalMs?: number | undefined; queueAhead?: number | undefined; comfyVersion?: string | undefined; /** Saved file path on workspace disk if savedTo was returned */ savedTo?: string | undefined; /** Whether this item is marked as favorite */ isFavorite?: boolean | undefined; /** Custom tags or collection markers */ tags?: string[] | undefined; /** Workspace filesystem path where the image was generated/saved */ workspacePath?: string | undefined; /** Workspace ID if known */ workspaceId?: string | undefined; /** Conversation session ID where the image was generated */ sessionId?: string | undefined; /** Attachment ids of the source images this image was edited from; used by the canvas to rebuild edit chains. Optional so records written by older versions stay readable. */ sourceAttachmentIds?: string[] | undefined; } /** A user-created folder grouping favorite prompts. */ export interface FavoriteFolder { id: string; kind: 'image' | 'prompt'; name: string; addedAt: number; } /** A prompt kept in the workbench favorites rail. */ export interface FavoritePrompt { /** Stable id derived from the trimmed text; identical prompts dedupe. */ id: string; text: string; addedAt: number; /** Owning folder id; absent entries are unfiled and appear under "all". */ folderId?: string; } type GalleryListener = () => void; /** * Subscribe to gallery mutations (insert/delete/clear). */ export declare function subscribeGallery(listener: GalleryListener): () => void; /** * Save or update a gallery record by attachmentId. * Skipped if the item was previously deleted (tombstoned). * Preserves existing isFavorite, tags, and original createdAt on re-renders. * Returns false when the record was not persisted (e.g. IndexedDB unavailable) * so callers can surface the failure and let the user retry. */ export declare function saveGalleryItem(item: Omit & { createdAt?: number; }): Promise; /** * Retrieve all gallery records sorted by createdAt descending. */ export declare function getGalleryItems(): Promise; /** * Toggle favorite status of a gallery item. * Returns the new favorite status (true if favorited, false if unfavorited). */ export declare function toggleFavoriteGalleryItem(id: string): Promise; /** * Delete a single gallery record by ID and record a tombstone. */ export declare function deleteGalleryItem(id: string): Promise; /** * Bulk delete multiple gallery records by IDs and record tombstones in a single transaction. */ export declare function bulkDeleteGalleryItems(ids: string[]): Promise; /** * Bulk update favorite status for multiple gallery records in a single transaction. */ export declare function bulkSetFavoriteGalleryItems(ids: string[], isFavorite: boolean): Promise; /** * Clear all gallery records and reset tombstones. */ export declare function clearGallery(): Promise; /** * Standardize path format across Windows and POSIX (lowercase, forward slashes, no trailing slash). */ export declare function normalizeWorkspacePath(rawPath: string): string; /** * Determine if a gallery item belongs to the given workspace context. * Compares workspaceId, sessionId membership, workspacePath, and savedTo file path prefix. */ export declare function isItemInWorkspace(item: GalleryItem, workspace?: { workspaceId?: string | undefined; path?: string | undefined; sessionIds?: readonly string[] | undefined; } | null): boolean; /** Subscribe to favorites mutations (insert/delete). */ export declare function subscribeFavorites(listener: () => void): () => void; /** * Keep one prompt in the favorites rail; identical trimmed text overwrites * (one record per distinct prompt). * @returns false when the write failed. */ export declare function saveFavoritePrompt(text: string): Promise; /** Prompt favorites, newest first. */ export declare function getFavoritePrompts(): Promise; /** Drop one prompt favorite. */ export declare function deleteFavoritePrompt(id: string): Promise; /** Create a favorites folder; returns null when the name is empty or already used for the kind. */ export declare function addFavoriteFolder(kind: 'image' | 'prompt', name: string): Promise; /** List all favorite folders. */ export declare function getFavoriteFolders(): Promise; /** Delete a folder; member favorites survive and become unfiled. */ export declare function deleteFavoriteFolder(id: string): Promise; /** File a favorite prompt into a folder (undefined unfiles it). */ export declare function moveFavoritePrompt(id: string, folderId: string | undefined): Promise; /** Rewrite a favorite prompt's text in place, keeping its id stable. */ export declare function updateFavoritePrompt(id: string, text: string): Promise; export {};