UNPKG

use-vibes

Version:

Transform any DOM element into an AI-powered micro-app

76 lines (75 loc) 2.42 kB
import type { DocFileMeta, Database } from 'use-fireproof'; import { ImageGenOptions, ImageResponse } from 'call-ai'; export interface PromptEntry { text: string; created: number; } export interface ImageDocument { _id?: string; type?: 'image'; prompt?: string; _files?: Record<string, File | DocFileMeta>; created?: number; currentVersion?: number; versions?: VersionInfo[]; prompts?: Record<string, PromptEntry>; currentPromptKey?: string; } export interface VersionInfo { id: string; created: number; promptKey?: string; } export type GenerationPhase = 'idle' | 'generating' | 'complete' | 'error'; /** Input options for the useImageGen hook */ export interface UseImageGenOptions { /** Prompt text for image generation */ prompt?: string; /** Document ID for fetching existing image */ _id?: string; /** Fireproof database name or instance */ database?: string | Database; /** Image generator options */ options?: ImageGenOptions; /** * Generation ID - a unique identifier that changes ONLY when a fresh request is made. * This replaces the regenerate flag with a more explicit state change signal. */ generationId?: string; /** Flag to skip processing when neither prompt nor _id is valid */ skip?: boolean; /** * Edited prompt that should override the document prompt on regeneration * This is used when the user edits the prompt in the UI before regenerating */ editedPrompt?: string; } export interface UseImageGenResult { /** Base64 image data */ imageData: string | null; /** Whether the image is currently loading */ loading: boolean; /** Progress percentage (0-100) */ progress: number; /** Error if image generation failed */ error: Error | null; /** Size information parsed from options */ size: { width: number; height: number; }; /** Document for the generated image */ document: ImageDocument | null; } export interface ModuleState { pendingImageGenCalls: Map<string, Promise<ImageResponse>>; pendingPrompts: Set<string>; processingRequests: Set<string>; requestTimestamps: Map<string, number>; requestCounter: number; createdDocuments: Map<string, string>; pendingDocumentCreations: Map<string, Promise<{ id: string; doc: ImageDocument; }>>; }