Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

4.3 KB
Raw Blame
// The picks of the one click swap (14.11.2026, only with the account switch;
// port of the web's lib/create/swap-one-click.ts): which editor builds the
// first frame and which engine makes the video. Without an own pick the
// number of people and the switch "Uncensored" decide.
//   1 person   SCAIL 2 (Kling only when picked under More options)
//   2 to 3     SCAIL 2
//   4          OpenJutsu, one step as before
// Without React; the panel (hub/SwapOneClick.tsx) only holds the state.

import { create } from 'zustand'
import { STUDIO_MODELS } from '../render/studio-contract'
import {
  swapAutoModel, swapFrameEditors, swapFrameModelFor, swapMaxPeople, swapUsesFrame,
  SWAP_FRAME_MODEL, SWAP_FRAME_OPEN_MODEL, SWAP_INTENT, SWAP_KLING_MODEL, SWAP_LONG_MODEL, SWAP_MAIN_MODEL, SWAP_OPENJUTSU_MODEL,
} from '../render/swap'

/** The engines "Video ▾" offers. */
export const SWAP_VIDEO_CHOICES: readonly string[] = [SWAP_MAIN_MODEL, SWAP_KLING_MODEL, SWAP_OPENJUTSU_MODEL, SWAP_LONG_MODEL]

/** The engine of the video: the own pick while it can take this many people,
 *  else automatic by the number of people. */
export function swapVideoModelFor(people: number, override: string | null): string {
  const n = Math.max(1, people)
  if (override && SWAP_VIDEO_CHOICES.includes(override) && swapMaxPeople(override) >= n) return override
  return swapAutoModel(n)
}

/** Why an engine cannot take this many people, or null. */
export function swapVideoBlocked(model: string, people: number): string | null {
  const max = swapMaxPeople(model)
  if (Math.max(1, people) <= max) return null
  return max === 1 ? 'one person only' : `up to ${max} people`
}

/** Does the swap run on this engine as a chain (frame, then video)? */
export function swapIsChain(videoModel: string): boolean {
  return swapUsesFrame(SWAP_INTENT, videoModel)
}

/** The name of a model as the bar shows it ("SCAIL-2", "Nano Banana Pro"). */
export function swapModelName(id: string): string {
  if (id === SWAP_MAIN_MODEL) return 'SCAIL-2'
  if (id === SWAP_KLING_MODEL) return 'Kling 3.0 Pro'
  return STUDIO_MODELS[id]?.label ?? id
}

/** The grey line under "Uncensored": what runs with and without the switch. */
export function swapOpenModelsLine(videoModel: string): string {
  return `Off: ${swapModelName(SWAP_FRAME_MODEL)} + ${swapModelName(videoModel)}. On: open-weight models, less strict.`
}

/** The picks of "First frame ▾": Auto and every editor that reads two images. */
export function swapFrameChoices(openModels: boolean): { value: string; label: string }[] {
  const auto = swapFrameModelFor(openModels, null)
  return [
    { value: '', label: `Auto (${swapModelName(auto)})` },
    ...swapFrameEditors().map((id) => ({ value: id, label: swapModelName(id) })),
  ]
}

export interface SwapOneClickPrefs {
  /** The switch "Uncensored" (on the web "Open models"). */
  openModels: boolean
  check: boolean
  /** The customer set "Check first frame" by hand: from then on it no longer
   *  follows "Uncensored". */
  checkTouched: boolean
  /** Editor under More options, '' = Auto. */
  frameOverride: string
  /** Engine under More options, '' = Auto. */
  videoOverride: string
  setOpenModels: (v: boolean) => void
  /** The customer's own pick of "Check first frame". */
  setCheck: (v: boolean) => void
  setFrameOverride: (v: string) => void
  setVideoOverride: (v: string) => void
}

/** "Check first frame" by default: on with "Uncensored", off without it
 *  (David's call, 14.11.2026: the open editor is less sure, the customer
 *  sees its frame before paying for the video). */
export function swapCheckDefault(openModels: boolean): boolean {
  return openModels
}

/** Both switches start off (David's call). Turning "Uncensored" on or off
 *  takes "Check first frame" along to its default, unless the customer set
 *  that switch by hand. */
export const useSwapOneClick = create<SwapOneClickPrefs>((set) => ({
  openModels: false,
  check: swapCheckDefault(false),
  checkTouched: false,
  frameOverride: '',
  videoOverride: '',
  setOpenModels: (openModels) => set((s) => (s.checkTouched ? { openModels } : { openModels, check: swapCheckDefault(openModels) })),
  setCheck: (check) => set({ check, checkTouched: true }),
  setFrameOverride: (frameOverride) => set({ frameOverride }),
  setVideoOverride: (videoOverride) => set({ videoOverride }),
}))

export { SWAP_FRAME_MODEL, SWAP_FRAME_OPEN_MODEL }