Class FallbackImageProxy

An IImageProvider that wraps an ordered chain of image providers and implements automatic failover for every operation.

Retry chain logic

Providers are tried left-to-right (index 0 first). The first provider that succeeds returns immediately. When a provider throws:

  • If it is NOT the last provider: a image:fallback event is emitted and the next provider is tried.
  • If it IS the last provider: an AggregateError containing every collected error is thrown.
  • If the chain is empty: an Error('No providers in image fallback chain') is thrown immediately.

For optional operations (edit/upscale/variate), providers that do not implement the method or throw a *NotSupportedError are silently skipped, since they are structurally incapable rather than transiently failing.

Implements

Constructors

  • Creates a new FallbackImageProxy wrapping the given provider chain.

    Parameters

    • chain: IImageProvider[]

      Ordered list of image providers to try. Must contain at least one entry for operations to succeed (an empty chain always throws).

    • emitter: EventEmitter<DefaultEventMap>

      EventEmitter on which image:fallback events are published so callers can observe the failover path.

    Returns FallbackImageProxy

    Example

    const proxy = new FallbackImageProxy(
    [openaiProvider, stabilityProvider],
    new EventEmitter(),
    );

Methods

Properties

providerId: string

Identifier derived from the first provider in the chain.

isInitialized: boolean = true

Always true — the proxy is ready as soon as it is constructed.

defaultModelId?: string

Default model from the first provider, if set.