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.

5.4 KB
Raw Blame
import type { ProjectGraphAction } from '@features/workflow/core/document';
import type { ForLoopValidationReason } from '@features/workflow/core/forLoops';
import type { ProjectGraphState, ProjectWorkflowSource, XYPosition } from '@features/workflow/core/types';
import type { LogSource } from '@platform/logging/contracts';
import type { ReactNode } from 'react';

export type WorkflowRegion = 'left' | 'right' | 'bottom' | 'center' | 'dialog' | 'popover' | 'floating';

/**
 * Mirror Workbench regions structurally; app/WorkflowUiAdapter widgets wiring catches drift without a forbidden
 * feature-to-workbench import.
 */
export type WorkflowWidgetPanelRegion = 'left' | 'right' | 'bottom' | 'center';

/**
 * Mirror invocation source IDs structurally; adapter and WidgetActionsMenu wiring provide type checks across the
 * ownership boundary.
 */
export type WorkflowInvocationSourceId = 'generate' | 'workflow' | 'upscale' | 'video' | 'canvas';

export interface WorkflowRuntimeApi {
  instanceId: string;
  typeId: string;
  region: WorkflowRegion;
  commands: {
    register(command: { id: string; title: string; handler: () => unknown }): () => void;
  };
  hotkeys: {
    register(hotkey: { id: string; commandId: string; defaultKeys: string[]; title: string }): () => void;
  };
}

export interface WorkflowWidgetViewProps {
  region: WorkflowRegion;
  runtime: WorkflowRuntimeApi;
  presentation?: 'compact' | 'expanded' | 'tooltip';
}

export interface WorkflowWidgetLabelProps {
  region: WorkflowRegion;
  presentation?: 'compact' | 'expanded' | 'tooltip';
}

/** Where an edit or history step lands; absent means the active project's active workflow. */
export interface WorkflowTarget {
  projectId: string;
  workflowId: string;
}

export interface WorkflowCommands {
  /** Adds and activates a document in the active project; returns the id the project knows it by. */
  addWorkflow(
    document: ProjectGraphState,
    options: { label: string; reusePlaceholder?: boolean; source?: ProjectWorkflowSource }
  ): string;
  createWorkflow(): string;
  duplicateWorkflow(workflowId: string, copyName: string): string | null;
  editGraph(action: ProjectGraphAction, target?: WorkflowTarget): void;
  redo(target?: WorkflowTarget): void;
  removeWorkflow(workflowId: string): void;
  /** Renames a workflow of the active project, or of `projectId` when given; ignored once it no longer exists. */
  renameWorkflow(workflowId: string, name: string, projectId?: string): void;
  /** Replaces a copy's document (keeping its id and name) as one undo step, and activates it. */
  replaceWorkflow(
    target: WorkflowTarget,
    document: ProjectGraphState,
    options: { label: string; source: ProjectWorkflowSource }
  ): void;
  selectWorkflow(workflowId: string): void;
  /** Records a publication target; ignored once that project or workflow no longer exists. */
  setWorkflowSource(target: WorkflowTarget, source: ProjectWorkflowSource | undefined): void;
  undo(target?: WorkflowTarget): void;
}

export interface WorkflowWidgetCommands {
  open(options: { region: WorkflowWidgetPanelRegion; widgetId: string }): void;
  patchValues(widgetId: string, values: Record<string, unknown>): void;
}

export interface WorkflowNodeExecutionState {
  status: 'running' | 'completed' | 'failed';
  progress: number | null;
  progressMessage: string | null;
  /** The node's most recent image output, when it produced one. */
  outputImageName: string | null;
  /** The most recent invocation result of the current run. */
  latestOutput: unknown;
  error: string | null;
}

export interface WorkflowPreviewGraph {
  id: string;
  label?: string;
  updatedAt?: string;
  version?: 1;
  nodes: Array<{ id: string; type: string; inputs: Record<string, unknown> }>;
  edges: Array<{
    id: string;
    sourceNodeId: string;
    sourceField: string;
    targetNodeId: string;
    targetField: string;
    type?: 'default' | 'loop_linkage';
  }>;
  backendGraph?: unknown;
}

export interface GraphPreviewNotice {
  id: string;
  message: string;
  nodeId?: string;
}

export interface GraphPreviewSummaryRow {
  id: string;
  label: string;
  value: string;
}

export interface GraphPreviewProvenance {
  label: string;
}

/** The host's Invoke for a graph preview's source, rendered by the host (the preview owns no route). */
export interface GraphPreviewInvoke {
  control: ReactNode;
  /** Whether that Invoke can run now; its control says why not. */
  isReady: boolean;
}

export interface GraphPreviewSourceState {
  graph: WorkflowPreviewGraph | null;
  /**
   * The workflow document the graph compiles from, when there is one: the preview draws it, so its labels, notes and
   * form show; `graph` stays what runs.
   */
  document?: ProjectGraphState;
  /** Human-readable result destination (e.g. "Gallery"), set for every source by the builder. */
  destinationLabel: string | null;
  invalidReasons: Array<string | ForLoopValidationReason>;
  /** Recompiled from current project state, rather than a saved compiled graph replayed; sets the dialog subtitle. */
  isLive: boolean;
  notices: GraphPreviewNotice[];
  positionHints?: Record<string, XYPosition>;
  /** nodeId → field → display text, for fields whose real value the preview can't show verbatim (e.g. a randomized seed). */
  resolvedInputOverrides?: Record<string, Record<string, string>>;
  summaryRows: GraphPreviewSummaryRow[];
  getProvenance?: (nodeId: string, fieldName: string) => GraphPreviewProvenance | null;
}

export type WorkflowPerfSource = LogSource;