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 { VideoWidgetValues } from '@features/video/core/types';

/** Patches recreate values, so memo and reconciliation boundaries compare content. */

const stableStringify = (value: unknown): string => JSON.stringify(value ?? null);

export const areVideoModelsEquivalent = (
  left: { key: string; hash?: string } | null,
  right: { key: string; hash?: string } | null
): boolean => (left === null && right === null) || (left?.key === right?.key && left?.hash === right?.hash);

export const areVideoLorasEquivalent = (left: VideoWidgetValues['loras'], right: VideoWidgetValues['loras']): boolean =>
  left.length === right.length &&
  left.every(
    (lora, index) =>
      lora.model.key === right[index]?.model.key &&
      lora.model.name === right[index]?.model.name &&
      lora.model.hash === right[index]?.model.hash &&
      lora.weight === right[index]?.weight &&
      lora.target === right[index]?.target &&
      lora.lowNoiseWeight === right[index]?.lowNoiseWeight &&
      lora.isEnabled === right[index]?.isEnabled
  );

export const areVideoValuesEqual = (left: VideoWidgetValues, right: VideoWidgetValues): boolean => {
  if (left === right) {
    return true;
  }

  return (
    left.modelKey === right.modelKey &&
    left.h3TaskOverride === right.h3TaskOverride &&
    left.model?.variant === right.model?.variant &&
    areVideoModelsEquivalent(left.model, right.model) &&
    left.positivePrompt === right.positivePrompt &&
    left.negativePrompt === right.negativePrompt &&
    left.negativePromptEnabled === right.negativePromptEnabled &&
    left.positivePromptHeightPx === right.positivePromptHeightPx &&
    left.dynamicPromptsCombinatorial === right.dynamicPromptsCombinatorial &&
    left.dynamicPromptsEnabled === right.dynamicPromptsEnabled &&
    left.dynamicPromptsMaxPrompts === right.dynamicPromptsMaxPrompts &&
    left.dynamicPromptsResample === right.dynamicPromptsResample &&
    left.dynamicPromptsSampleSeed === right.dynamicPromptsSampleSeed &&
    left.dynamicPromptsSeedBehaviour === right.dynamicPromptsSeedBehaviour &&
    left.negativePromptHeightPx === right.negativePromptHeightPx &&
    left.aspectRatioId === right.aspectRatioId &&
    left.targetResolution === right.targetResolution &&
    left.numFrames === right.numFrames &&
    left.fps === right.fps &&
    left.steps === right.steps &&
    left.cfgScale === right.cfgScale &&
    left.cfgScaleLowNoise === right.cfgScaleLowNoise &&
    left.audioCfgScale === right.audioCfgScale &&
    left.stgScale === right.stgScale &&
    left.modalityScale === right.modalityScale &&
    left.acceleratorEnabled === right.acceleratorEnabled &&
    stableStringify(left.acceleratorLoraKeys) === stableStringify(right.acceleratorLoraKeys) &&
    left.seed === right.seed &&
    left.seedMode === right.seedMode &&
    left.batchCount === right.batchCount &&
    areVideoLorasEquivalent(left.loras, right.loras) &&
    stableStringify(left.firstFrameImage) === stableStringify(right.firstFrameImage) &&
    stableStringify(left.lastFrameImage) === stableStringify(right.lastFrameImage) &&
    stableStringify(left.references) === stableStringify(right.references) &&
    stableStringify(left.sourceVideo) === stableStringify(right.sourceVideo) &&
    stableStringify(left.conditioningClip) === stableStringify(right.conditioningClip) &&
    stableStringify(left.vae) === stableStringify(right.vae) &&
    stableStringify(left.wanT5EncoderModel) === stableStringify(right.wanT5EncoderModel) &&
    stableStringify(left.wanLowNoiseModel) === stableStringify(right.wanLowNoiseModel) &&
    stableStringify(left.componentSourceModel) === stableStringify(right.componentSourceModel) &&
    stableStringify(left.h3TransformerModel) === stableStringify(right.h3TransformerModel) &&
    stableStringify(left.h3TextEncoderModel) === stableStringify(right.h3TextEncoderModel) &&
    stableStringify(left.ltx2TextEncoderModel) === stableStringify(right.ltx2TextEncoderModel) &&
    stableStringify(left.ltx2DurationHeadModel) === stableStringify(right.ltx2DurationHeadModel) &&
    left.autoDuration === right.autoDuration &&
    stableStringify(left.h3HybridBaseModel) === stableStringify(right.h3HybridBaseModel) &&
    left.h3HybridStartBlock === right.h3HybridStartBlock
  );
};