Skip to content

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.

4.2 KB
Raw Blame
import type {
  CanvasControlDerivationCapability,
  CommitGeneratedImageOptions,
  CommitGeneratedImageResult,
  ExportBakedLayerBlobResult,
  ExportLayerPixelsOptions,
  LayerExportGuard,
  ReplaceSelectionFromImageResult,
} from '@workbench/canvas-engine/capabilities';
import type { CanvasDocumentContractV3, CanvasImageRef } from '@workbench/canvas-engine/contracts';
import type {
  CommitRasterFilterOptions,
  CommitRasterFilterResult,
} from '@workbench/canvas-engine/controllers/filterResultController';
import type {
  CommitMaskImageResult,
  CommitMaskImageResultOptions,
} from '@workbench/canvas-engine/controllers/maskResultController';
import type { LayerFlushOptions, LayerFlushResult } from '@workbench/canvas-engine/controllers/persistenceController';
import type { LayerUnreadable } from '@workbench/canvas-engine/layerExportGuards';
import type { CanvasCompositeExecutorDeps } from '@workbench/canvas-engine/rasterTransactions';
import type { AdjustmentRefusal } from '@workbench/canvas-engine/render/exactAdjustments';
import type { RasterSurface } from '@workbench/canvas-engine/render/raster';
import type { SamInteractionState, SamVisualInput } from '@workbench/canvas-engine/samInteraction';
import type { Rect } from '@workbench/canvas-engine/types';

export type SelectObjectStartContext =
  | { status: 'missing' | 'disabled' | 'locked' | 'unsupported' | 'not-ready' }
  | {
      status: 'ready';
      guard: LayerExportGuard;
      layerId: string;
      layerName: string;
      layerType: 'raster' | 'control';
      sourceRect: Rect;
    };

/**
 * Narrow core primitives used only by application-level canvas coordinators, including the control derivation commits
 * the detection coordinator lands its intents and maps through.
 */
export interface CanvasApplicationHost extends CanvasControlDerivationCapability {
  captureGuard(layerId: string): LayerExportGuard | null;
  clearFilterPreview(layerId: string): void;
  clearSamPreview(): void;
  commitFilter(options: CommitRasterFilterOptions): Promise<CommitRasterFilterResult>;
  commitGenerated(options: CommitGeneratedImageOptions): Promise<CommitGeneratedImageResult>;
  commitMask(options: CommitMaskImageResultOptions): Promise<CommitMaskImageResult>;
  decodeSelectObjectPreview(result: { image: CanvasImageRef; rect: Rect }, signal: AbortSignal): Promise<RasterSurface>;
  encodeSurface(surface: RasterSurface): Promise<Blob>;
  exportBakedLayerBlob(layerId: string): Promise<ExportBakedLayerBlobResult>;
  /** Persists one layer's unsaved paint, so work reading its persisted source sees every stroke. */
  flushLayerUploads(layerId: string, options: LayerFlushOptions): Promise<LayerFlushResult>;
  exportLayerPixels(
    layerId: string,
    options?: ExportLayerPixelsOptions
  ): Promise<
    | { status: 'ok'; surface: RasterSurface; rect: Rect; guard: LayerExportGuard; release(): void }
    | { status: 'missing' | 'disabled' | 'unsupported' | 'empty' | 'not-ready' | 'over-budget' }
    | LayerUnreadable
    | AdjustmentRefusal
  >;
  getCompositeExecutorDeps(): CanvasCompositeExecutorDeps;
  getDocument(): CanvasDocumentContractV3 | null;
  isGuardCurrent(guard: LayerExportGuard): boolean;
  isSamToolActive(): boolean;
  prepareSelectObjectStart(layerId: string): SelectObjectStartContext;
  publishFilterPreview(
    layerId: string,
    imageName: string,
    rect: Rect,
    guard: LayerExportGuard,
    filterType?: string
  ): Promise<'shown' | 'missing' | 'stale'>;
  publishSamPreview(preview: {
    data: RasterSurface;
    guard: LayerExportGuard;
    isolated: boolean;
    rect: Rect;
  }): undefined;
  replaceSelection(
    guard: LayerExportGuard,
    image: CanvasImageRef,
    rect: Rect,
    signal?: AbortSignal
  ): Promise<ReplaceSelectionFromImageResult>;
  replaceTemporaryRestoreTool(): void;
  selectLayer(layerId: string): void;
  setSamInputHandler(handler: ((input: SamVisualInput) => void) | null): void;
  setEscapeHandler(handler: ((gestureWasActive: boolean) => boolean) | null): void;
  setSamInteraction(state: SamInteractionState | null): void;
  setSamTool(): void;
  setViewTool(): void;
  subscribeToolChanges(listener: (change: { from: string; to: string; temporary: boolean }) => void): () => void;
}