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.

18.8 KB
Raw Blame
// Cloud discovery sheet (2.5.8): Local mode surfaces the hosted-only Create
// tools + hosted models as tappable teasers, and THIS is what a tap opens — a
// small sheet with an animated "show me" demo of the tool, one line of copy,
// and the path into LU Cloud. Never blocks a local flow (it only opens from
// explicitly cloud-tagged surfaces), never shows in cloud mode. Closing it is
// only closing; the footer link is the one thing here that turns the whole
// discovery layer off (Settings can re-enable).

import { useEffect, useState } from 'react'
import { AnimatePresence, motion } from 'framer-motion'
import { useDismissOnEscape } from '../../hooks/useDismissOnEscape'
import { X, Cloud, Sparkles, MonitorDown } from 'lucide-react'
import { useUIStore, type CloudTeaserTarget } from '../../stores/uiStore'
import { useSettingsStore } from '../../stores/settingsStore'
import { cloudModelById } from '../../stores/cloudCatalogStore'
import { useCreateStore, type CreateIntent } from '../../stores/createStore'
import { isIntentAvailable } from '../create/experimental/intents'
import { isMlxImageHost } from '../../api/mlx-image'
import { mlxMakesMusic } from '../../lib/mac-music'
import { mlxFollowsMotion, mlxTalking } from '../../api/mlx-video'
import { openExternal, isMacOS } from '../../api/backend'
import { checkoutStartUrl } from '../../lib/cloud-links'
import { reportCloudGate } from '../../api/funnel'
import { BuyChoice } from './BuyChoice'
import { getMaxVramGb, getSharedMemoryGb } from '../../lib/hardware'
import { sharedMemoryWording } from '../../lib/shared-memory-wording'

interface TeaserCopy {
  title: string
  line: string
}

const INTENT_COPY: Record<Extract<CloudTeaserTarget, { surface: 'intent' }>['intent'], TeaserCopy> = {
  upscale: {
    title: 'Upscale',
    line: 'Blow any image up to crisp 2K, 4K or 8K. No VRAM needed.',
  },
  eraser: {
    title: 'Erase Object',
    line: 'Paint over anything and it’s gone. Clean fill, no trace.',
  },
  character: {
    title: 'Character Studio',
    line: 'Train a character from a few photos, then put them in any scene.',
  },
  lipsync: {
    title: 'Talking Character',
    line: 'A portrait plus any voice becomes a talking video.',
  },
  music: {
    title: 'Music',
    line: 'Describe a track, get a full song. Up to four minutes.',
  },
  extend: {
    title: 'Extend Video',
    line: 'Keep a clip going. The cloud continues it seamlessly.',
  },
  motion: {
    title: 'Motion Control',
    line: 'Your character copies the moves from any dance or pose video.',
  },
  swap_character: {
    title: 'Swap Character',
    line: 'Put a new person into a real video. Same moves, same scene, same sound.',
  },
}

/**
 * Where the tool on the sheet runs, as one sentence. `hasLocalLane`: it also
 * runs on this machine. `sharedMemory`: this machine is a Mac, which is not a
 * PC and has no VRAM. Today no lane with a sheet runs locally on a Mac (only
 * MLX image and video do, and they open no sheet), so the Mac half of the
 * first sentence waits for the first lane that does; it is written now so
 * that lane cannot ship with "your PC" in it.
 */
export function teaserWhereLine(hasLocalLane: boolean, sharedMemory: boolean): string {
  if (hasLocalLane) {
    return sharedMemory
      ? 'Runs on this Mac with downloaded models, or on LU Cloud where datacenter GPUs do the heavy lifting.'
      : 'Runs on your PC with downloaded models, or on LU Cloud where datacenter GPUs do the heavy lifting.'
  }
  return sharedMemoryWording('Runs on LU Cloud, where datacenter GPUs do the heavy lifting and VRAM is not the limit.', sharedMemory)
}

export function CloudTeaserModal() {
  const target = useUIStore((s) => s.cloudTeaser)
  const setCloudTeaser = useUIStore((s) => s.setCloudTeaser)
  const setCloudHiddenNotice = useUIStore((s) => s.setCloudHiddenNotice)
  const setIntent = useCreateStore((s) => s.setIntent)
  // Enhance Image runs on a Mac with an upscaler installed (SeedVR2).
  const mlxUpscale = useCreateStore((s) => s.mlxUpscale)
  // The one lane of these a Mac runs itself, while its music engine is there.
  const mlxMusic = useCreateStore((s) => mlxMakesMusic(s.audioModelList))
  // And Motion Control while an installed LTX-2.3 pack follows a motion video.
  const mlxMotion = useCreateStore((s) => mlxFollowsMotion(s.videoModelList))
  // And Talking Character, while a video model that talks is installed.
  const mlxTalk = useCreateStore((s) => mlxTalking(s.videoModelList).tab)
  const { updateSettings } = useSettingsStore()
  // The card's own number (2026-09-07): "Your GPU has 6 GB" says why
  // the tool is greyed out better than any adjective. Read once per opening,
  // from the same detect_gpus the hardware settings use; null when nothing
  // was found, and then the line falls back to the wording without a number.
  const [gpuGb, setGpuGb] = useState<number | null>(null)
  // A Mac has no card and is not a PC: one memory pool, read from the Apple
  // entry of detect_gpus (shared_memory_mib) with system_info behind it. The
  // sheet then says "This Mac has 16 GB of memory" and "Runs on this Mac".
  // `gpuGb` stays null there, so the checkout tag below never files a Mac's
  // memory as a card size.
  const sharedMemory = isMacOS()
  const [macMemoryGb, setMacMemoryGb] = useState<number | null>(null)
  useEffect(() => {
    if (!target) return
    let alive = true
    if (sharedMemory) {
      void getSharedMemoryGb().then((pool) => {
        if (alive) setMacMemoryGb(pool > 0 ? Math.round(pool) : null)
      })
    } else {
      void getMaxVramGb().then((gb) => {
        if (alive) setGpuGb(gb > 0 ? Math.round(gb) : null)
      })
    }
    return () => { alive = false }
  }, [target, sharedMemory])

  // Closing the sheet changes nothing (the box, 03.10.2026). From 2026-07-19
  // until 3.0.5 every way out of it (Escape, a click beside it, X, "Not now",
  // both buttons) also switched "Show Cloud features in Local mode" off, so
  // one Escape silently took the LU Cloud group out of the model pickers. The
  // setting now has exactly one control on this sheet, the link at the bottom
  // that says what it does, and the switch in Settings, General.
  const close = () => setCloudTeaser(null)
  const hideCloudFeatures = () => {
    reportCloudGate('cloud_teaser_hide')
    updateSettings({ cloudTeasersEnabled: false })
    setCloudTeaser(null)
    // The tabs and rows vanish with this click, so Create says where they
    // come back (CloudHiddenNotice).
    setCloudHiddenNotice(true)
  }
  // 2.5.8: the lanes that ALSO run locally get a "Try local" path — the sheet
  // stops being a pure upsell and becomes the fork between the two lanes.
  // Ask the same rule the IntentBar renders from, not a static op list: on the
  // Mac only MLX image/video run locally, so a list-based answer offered a
  // "Try local" button for lanes the bar doesn't even show (MAC-2).
  const localLane =
    target?.surface === 'intent' &&
    isIntentAvailable(target.intent as CreateIntent, 'local', isMlxImageHost(), false, false, mlxUpscale, mlxMusic, mlxMotion, mlxTalk)
      ? target.intent
      : null
  const copy: TeaserCopy | null =
    target?.surface === 'intent'
      ? INTENT_COPY[target.intent]
      : target?.surface === 'create-model'
        ? {
            title: cloudModelById(target.modelId)?.label ?? 'Hosted model',
            line:
              target.kind === 'video'
                ? 'Cinema grade video models on datacenter GPUs. No download, no VRAM limit.'
                : 'Frontier image models on datacenter GPUs. No download, no VRAM limit.',
          }
        : null


  useDismissOnEscape(!!target && !!copy, close)
  return (
    <AnimatePresence>
      {target && copy && (
        <motion.div
          initial={{ opacity: 0 }}
          animate={{ opacity: 1 }}
          exit={{ opacity: 0 }}
          className="fixed inset-0 z-[90] flex overflow-y-auto overscroll-contain p-4 lu-dialog-scrim"
          onClick={close}
        >
          <motion.div
            initial={{ opacity: 0, y: 10, scale: 0.97 }}
            animate={{ opacity: 1, y: 0, scale: 1 }}
            exit={{ opacity: 0, y: 10, scale: 0.97 }}
            transition={{ duration: 0.15, ease: 'easeOut' }}
            onClick={(e) => e.stopPropagation()}
            role="dialog"
            aria-modal="true"
            aria-label={copy.title}
            className="m-auto shrink-0 w-[360px] max-w-[92vw] rounded-2xl lu-dialog overflow-hidden"
          >
            {/* Demo stage */}
            <div className="relative h-[130px] bg-black/30 border-b border-white/[0.06] overflow-hidden">
              <TeaserDemo target={target} />
              <button
                onClick={close}
                className="absolute top-2 right-2 p-1.5 rounded-md text-gray-500 hover:text-gray-200 hover:bg-white/10 transition-colors"
                title="Close"
                aria-label="Close"
              >
                <X size={14} />
              </button>
            </div>

            <div className="p-4 space-y-3">
              <div className="flex items-center gap-2">
                <Cloud size={14} className="text-violet-600 dark:text-violet-300" />
                <h3 className="text-[0.85rem] font-semibold text-white">{copy.title}</h3>
                <span className="ml-auto text-[0.55rem] font-medium uppercase tracking-widest text-violet-300/80">
                  LU Cloud
                </span>
              </div>
              <p className="text-[0.7rem] leading-relaxed text-gray-400">{sharedMemoryWording(copy.line, sharedMemory)}</p>
              <p className="text-[0.62rem] leading-relaxed text-gray-500" data-testid="cloud-teaser-where">
                {gpuGb !== null && `Your GPU has ${gpuGb} GB. `}
                {macMemoryGb !== null && `This Mac has ${macMemoryGb} GB of memory. `}
                {teaserWhereLine(localLane !== null, sharedMemory)}
              </p>
              {/* Abo und Paket gleichrangig (Funnel 3.1.0, Nr. 4). Bis dahin
                  verkaufte dieses Blatt nur das Hosted-Abo. Beide Knoepfe gehen
                  auf die Kaufseite, nicht zum Zahlungsanbieter: Hosted vorgewaehlt bzw.
                  das Paket (2026-09-07: "die Pricing-Seite ist eine
                  Entscheidung zu viel"). Das src-Wort nennt die Kartengroesse,
                  damit der Zaehler auf dem Server sagen kann, was dieses
                  Blatt bringt. */}
              <BuyChoice
                tone="sheet"
                onPick={(order) => {
                  close()
                  reportCloudGate(order === 'sub' ? 'cloud_teaser_sub' : 'cloud_teaser_pack')
                  const src = gpuGb !== null ? `gpu${gpuGb}` : 'gpu-unknown'
                  void openExternal(checkoutStartUrl({ order, src, medium: 'create-sheet' }))
                }}
              />
              <div className="flex items-center gap-2">
                {localLane && (
                  <button
                    onClick={() => { close(); setIntent(localLane) }}
                    className="flex-1 flex items-center justify-center gap-1.5 h-8 rounded-lg border border-white/15 text-gray-200 text-[0.7rem] font-semibold hover:bg-white/[0.06] transition-colors"
                  >
                    <MonitorDown size={12} /> Try local
                  </button>
                )}
                <button
                  onClick={close}
                  className="flex-1 px-3 h-8 rounded-lg text-[0.7rem] text-gray-400 hover:text-gray-200 hover:bg-white/[0.06] transition-colors"
                >
                  Not now
                </button>
              </div>
              <button
                onClick={hideCloudFeatures}
                title="Turns off Show Cloud features in Local mode. Settings, General turns it back on."
                className="w-full text-center t-micro text-gray-500 hover:text-gray-300 transition-colors pt-0.5"
              >
                Don't show Cloud features in Local mode
              </button>
            </div>
          </motion.div>
        </motion.div>
      )}
    </AnimatePresence>
  )
}

// ── "Show me" demos — tiny looping motion sketches, one per tool. Pure
// CSS/SVG so they ship inside the bundle (no media assets, theme-crisp). ──

function TeaserDemo({ target }: { target: CloudTeaserTarget }) {
  const kind = target.surface === 'intent' ? target.intent : target.kind === 'video' ? 'video-model' : 'image-model'
  switch (kind) {
    case 'upscale': return <UpscaleDemo />
    case 'eraser': return <EraserDemo />
    case 'character': return <CharacterDemo />
    case 'lipsync': return <LipsyncDemo />
    case 'music': return <MusicDemo />
    case 'extend': return <ExtendDemo />
    case 'motion': return <MotionDemo />
    default: return <ModelDemo video={kind === 'video-model'} />
  }
}

const LOOP = { duration: 2.6, repeat: Infinity, ease: 'easeInOut' as const }

function Stage({ children }: { children: React.ReactNode }) {
  return <div className="absolute inset-0 flex items-center justify-center">{children}</div>
}

function UpscaleDemo() {
  return (
    <Stage>
      <motion.div
        className="w-20 h-20 rounded-lg bg-gradient-to-br from-violet-500/60 to-sky-500/60"
        animate={{ filter: ['blur(6px)', 'blur(0px)', 'blur(0px)', 'blur(6px)'], scale: [0.8, 1.05, 1.05, 0.8] }}
        transition={{ ...LOOP, duration: 3.2, times: [0, 0.4, 0.7, 1] }}
      />
      <motion.span
        className="absolute text-[0.55rem] font-mono text-white/70"
        animate={{ opacity: [0, 0, 1, 0] }}
        transition={{ ...LOOP, duration: 3.2, times: [0, 0.4, 0.6, 1] }}
      >
        4K
      </motion.span>
    </Stage>
  )
}

function EraserDemo() {
  return (
    <Stage>
      <div className="relative w-24 h-16 rounded-lg bg-gradient-to-br from-emerald-800/60 to-emerald-600/40">
        {/* Der Gegenstand, den der Radierer wegnimmt. Er war gelb, ohne dass
            hier irgendetwas zu warnen waere: reine Deko. Sky gehoert zur
            Palette dieses Fensters (violet, sky, fuchsia, rose) und ist als
            volle Flaeche noch an keinen anderen Demo-Gegenstand vergeben. */}
        <motion.div
          className="absolute left-3 bottom-3 w-6 h-8 rounded-sm bg-sky-300/90"
          animate={{ opacity: [1, 1, 0, 0, 1] }}
          transition={{ ...LOOP, duration: 3, times: [0, 0.35, 0.55, 0.85, 1] }}
        />
        <motion.div
          className="absolute w-3.5 h-3.5 rounded-full border-2 border-white/80 bg-white/20"
          animate={{ x: [8, 20, 8], y: [18, 30, 18], opacity: [0, 1, 0] }}
          transition={{ ...LOOP, duration: 3 }}
        />
      </div>
    </Stage>
  )
}

function CharacterDemo() {
  return (
    <Stage>
      <div className="flex items-center gap-3">
        <div className="grid grid-cols-2 gap-1">
          {[0, 1, 2, 3].map((i) => (
            <motion.div
              key={i}
              className="w-5 h-5 rounded-sm bg-white/25"
              animate={{ opacity: [0.4, 1, 0.4] }}
              transition={{ ...LOOP, delay: i * 0.18 }}
            />
          ))}
        </div>
        <motion.div animate={{ x: [0, 3, 0] }} transition={LOOP} className="text-gray-500 text-[0.7rem]">→</motion.div>
        <motion.div
          className="w-12 h-12 rounded-full bg-gradient-to-br from-violet-400/70 to-fuchsia-400/70 flex items-center justify-center"
          animate={{ scale: [0.92, 1.06, 0.92] }}
          transition={LOOP}
        >
          <Sparkles size={14} className="text-white/90" />
        </motion.div>
      </div>
    </Stage>
  )
}

function LipsyncDemo() {
  return (
    <Stage>
      <div className="flex items-center gap-4">
        <div className="relative w-14 h-14 rounded-full bg-white/15 flex items-end justify-center pb-3">
          <div className="absolute top-4 flex gap-2.5">
            <span className="w-1.5 h-1.5 rounded-full bg-white/70" />
            <span className="w-1.5 h-1.5 rounded-full bg-white/70" />
          </div>
          <motion.div
            className="w-4 rounded-full bg-rose-300/90"
            animate={{ height: [2, 6, 3, 7, 2] }}
            transition={{ duration: 1.1, repeat: Infinity, ease: 'easeInOut' }}
          />
        </div>
        <div className="flex items-end gap-0.5 h-8">
          {[10, 18, 26, 16, 22, 12, 20].map((h, i) => (
            <motion.span
              key={i}
              className="w-1 rounded-full bg-violet-300/80"
              animate={{ height: [h * 0.4, h, h * 0.4] }}
              transition={{ duration: 0.9, repeat: Infinity, ease: 'easeInOut', delay: i * 0.09 }}
            />
          ))}
        </div>
      </div>
    </Stage>
  )
}

function MusicDemo() {
  return (
    <Stage>
      <div className="flex items-end gap-1 h-12">
        {[14, 26, 38, 22, 34, 18, 30, 24, 40, 16].map((h, i) => (
          <motion.span
            key={i}
            className="w-1.5 rounded-full bg-gradient-to-t from-violet-500/80 to-sky-400/80"
            animate={{ height: [h * 0.35, h, h * 0.35] }}
            transition={{ duration: 1.1, repeat: Infinity, ease: 'easeInOut', delay: i * 0.07 }}
          />
        ))}
      </div>
    </Stage>
  )
}

function ExtendDemo() {
  return (
    <Stage>
      <div className="flex items-center gap-1">
        {[0, 1, 2].map((i) => (
          <div key={i} className="w-8 h-12 rounded-sm bg-white/20 border border-white/10" />
        ))}
        {[3, 4].map((i) => (
          <motion.div
            key={i}
            className="w-8 h-12 rounded-sm bg-violet-400/50 border border-violet-300/30"
            animate={{ opacity: [0, 0, 1, 1, 0], x: [-6, -6, 0, 0, -6] }}
            transition={{ duration: 3, repeat: Infinity, ease: 'easeOut', times: [0, 0.2 + i * 0.12, 0.35 + i * 0.12, 0.85, 1] }}
          />
        ))}
      </div>
    </Stage>
  )
}

function MotionDemo() {
  return (
    <Stage>
      <div className="flex items-center gap-5">
        <motion.div
          className="w-8 h-14 rounded-md border-2 border-dashed border-white/40"
          animate={{ rotate: [-9, 9, -9] }}
          transition={LOOP}
        />
        <motion.div animate={{ opacity: [0.3, 1, 0.3] }} transition={LOOP} className="text-gray-500 text-[0.7rem]">→</motion.div>
        <motion.div
          className="w-8 h-14 rounded-md bg-gradient-to-b from-violet-400/80 to-fuchsia-500/70"
          animate={{ rotate: [-9, 9, -9] }}
          transition={{ ...LOOP, delay: 0.12 }}
        />
      </div>
    </Stage>
  )
}

function ModelDemo({ video }: { video: boolean }) {
  return (
    <Stage>
      <motion.div
        className={
          video
            ? 'w-24 h-14 rounded-lg bg-gradient-to-br from-sky-500/50 to-violet-500/50'
            : 'w-16 h-16 rounded-lg bg-gradient-to-br from-violet-500/50 to-fuchsia-500/50'
        }
        animate={{ scale: [0.94, 1.04, 0.94], opacity: [0.7, 1, 0.7] }}
        transition={LOOP}
      >
        <div className="w-full h-full flex items-center justify-center">
          <Cloud size={18} className="text-white/80" />
        </div>
      </motion.div>
    </Stage>
  )
}