@imgly/plugin-ai-image-generation-web
Version:
AI image generation plugin for the CE.SDK editor
117 lines (116 loc) • 3.45 kB
TypeScript
import { type OpenAPIV3 } from 'openapi-types';
import type CreativeEditorSDK from '@cesdk/cesdk-js';
import type { CreativeEngine } from '@cesdk/cesdk-js';
import { ImageOutput, RenderCustomProperty, GetBlockInput, Provider, Middleware } from '@imgly/plugin-ai-generation-web';
import { ImageQuickActionSupportMap } from '../types';
type MiddlewareType = Middleware<any, any>;
/**
* Configuration for EachLabs image providers.
*/
export interface EachLabsProviderConfiguration {
/**
* HTTP endpoint URL for the EachLabs proxy. The proxy handles API key injection.
*/
proxyUrl: string;
/**
* Enable debug logging for provider creation and API calls.
*/
debug?: boolean;
/**
* Middleware functions to process inputs/outputs.
*/
middlewares?: MiddlewareType[];
/**
* Override provider's default history asset source.
*/
history?: false | '@imgly/local' | '@imgly/indexedDB' | (string & {});
/**
* Configure supported quick actions.
*/
supportedQuickActions?: {
[quickActionId: string]: Partial<ImageQuickActionSupportMap<any>[string]> | false | null;
};
}
/**
* Options for creating an EachLabs image provider.
*/
interface CreateProviderOptions<I extends Record<string, any>> {
/**
* EachLabs model slug (e.g., 'nano-banana-pro').
*/
modelSlug: string;
/**
* EachLabs model version (e.g., '0.0.1').
*/
modelVersion: string;
/**
* Unique provider identifier for registration.
*/
providerId: string;
/**
* Human-readable provider name displayed in the UI.
*/
name: string;
/**
* OpenAPI schema document describing the input parameters.
*/
schema: OpenAPIV3.Document;
/**
* JSON reference to the input schema (e.g., '#/components/schemas/Input').
*/
inputReference: string;
/**
* User flow mode for the provider panel.
*/
useFlow?: 'placeholder' | 'generation-only';
/**
* Initialization callback when the provider is registered.
*/
initialize?: (context: {
cesdk?: CreativeEditorSDK;
engine: CreativeEngine;
}) => void;
/**
* Custom property renderers for the input panel.
*/
renderCustomProperty?: RenderCustomProperty;
/**
* Quick actions this provider supports.
*/
supportedQuickActions?: ImageQuickActionSupportMap<I>;
/**
* Get block dimensions from input parameters.
*/
getBlockInput?: GetBlockInput<'image', I>;
/**
* Extract image dimensions from input parameters.
*/
getImageSize?: (input: I) => {
width: number;
height: number;
};
/**
* Transform input parameters to EachLabs API format.
*/
mapInput: (input: I) => Record<string, any>;
/**
* Provider-specific middleware functions.
*/
middleware?: MiddlewareType[];
/**
* Custom headers to include in API requests.
*/
headers?: Record<string, string>;
/**
* CE.SDK instance for image URL conversion.
*/
cesdk?: CreativeEditorSDK;
}
/**
* Creates an EachLabs image provider from schema.
*/
declare function createImageProvider<I extends Record<string, any> & {
image_url?: string;
image_urls?: string[];
}>(options: CreateProviderOptions<I>, config: EachLabsProviderConfiguration): Provider<'image', I, ImageOutput>;
export default createImageProvider;