Model list cleanup: shared omni-gen hooks, dead code removal

This commit is contained in:
BFlat committed 2026-07-02 14:51:23 +07:00
1 parent b782cb0c67
commit 0734a12f9f
39 files changed
+818 -2837

No files matched your search

+1
View File
@@ -4,6 +4,7 @@
dist
tmp
out-tsc
*.tsbuildinfo
# dependencies
node_modules
@@ -5,9 +5,9 @@ import { faCube, faImage, faVideo } from "@fortawesome/pro-solid-svg-icons";
import { toast } from "../toast/toast";
import { downloadMediaFile } from "../../lib/download-media";
import {
getModelCreatorIconPath,
getCreatorIconPathForModelId,
getModelDisplayName,
} from "../../lib/omni-gen-hooks";
} from "@storyteller/model-list";
import {
applyMakeVideoFromImage,
applyRecreateFromMediaToken,
@@ -72,7 +72,7 @@ export function useGalleryItemActions(
? getModelDisplayName(effectiveModelId)
: null;
const modelIconPath = effectiveModelId
? getModelCreatorIconPath(effectiveModelId)
? getCreatorIconPathForModelId(effectiveModelId)
: null;
const handleRecreate = useCallback(
@@ -23,6 +23,7 @@ import { Button } from "@storyteller/ui-button";
import {
getProviderDisplayName,
getModelDisplayName,
getCreatorIconPathForModelId,
findModelByKey,
} from "@storyteller/model-list";
import { CloseButton } from "@storyteller/ui-close-button";
@@ -30,7 +31,6 @@ import dayjs from "dayjs";
import { ActionReminderModal } from "@storyteller/ui-action-reminder-modal";
import { Lightbox } from "../lightbox/lightbox";
import { showToast } from "../toast/toast";
import { getModelCreatorIconPath } from "../../lib/omni-gen-hooks";
import { useRecreateFromPromptToken } from "../../lib/recreate";
import { getMediaThumbnail, THUMBNAIL_SIZES } from "@storyteller/common";
import { twMerge } from "tailwind-merge";
@@ -263,7 +263,7 @@ const InProgressCard = ({
? formatTimeLeft(task.estimatedTimeLeftMs)
: null;
const modelIconPath = task.modelType
? getModelCreatorIconPath(task.modelType)
? getCreatorIconPathForModelId(task.modelType)
: null;
return (
@@ -1,313 +0,0 @@
import { useEffect, useState } from "react";
import { OmniGenApi } from "@storyteller/api";
import type {
OmniGenImageModelInfo,
OmniGenVideoModelInfo,
} from "@storyteller/api";
import { getModelDisplayName as getCanonicalModelDisplayName } from "@storyteller/model-list";
import { toast } from "../components/toast/toast";
// Shown when the OmniGen service is unavailable (e.g. returns 5xx). Separate
// copy for the two failure points so the user knows which step failed. The
// toast dedups on identical messages within a short window, so concurrent
// failures surface a single notice.
export const OMNI_MODELS_OUTAGE_MESSAGE =
"Couldn't load models - the generation service may be down. Try again shortly.";
export const OMNI_GENERATE_OUTAGE_MESSAGE =
"Couldn't start generation - the service is temporarily unavailable. Try again shortly.";
// ── Singleton caches (fetch once per session) ────────────────────────────
let imageModelsCache: OmniGenImageModelInfo[] | null = null;
let imageModelsFetching = false;
let imageModelsError: string | null = null;
let imageModelsListeners: Array<() => void> = [];
let videoModelsCache: OmniGenVideoModelInfo[] | null = null;
let videoModelsFetching = false;
let videoModelsError: string | null = null;
let videoModelsListeners: Array<() => void> = [];
function notifyImageListeners() {
imageModelsListeners.forEach((cb) => cb());
imageModelsListeners = [];
}
function notifyVideoListeners() {
videoModelsListeners.forEach((cb) => cb());
videoModelsListeners = [];
}
function fetchImageModelsOnce() {
if (imageModelsCache || imageModelsFetching) return;
imageModelsFetching = true;
imageModelsError = null;
const api = new OmniGenApi();
api.getImageModels().then(
(res) => {
imageModelsFetching = false;
if (res.success && res.models?.length) {
imageModelsCache = res.models.filter((m) => m.is_disabled !== true);
} else {
imageModelsError = "No image models returned from API";
console.warn("[OmniGen] Image models response:", res);
toast.error(OMNI_MODELS_OUTAGE_MESSAGE);
}
notifyImageListeners();
},
(err) => {
imageModelsFetching = false;
imageModelsError = err?.message ?? "Failed to fetch image models";
console.error("[OmniGen] Failed to fetch image models:", err);
toast.error(OMNI_MODELS_OUTAGE_MESSAGE);
notifyImageListeners();
},
);
}
function fetchVideoModelsOnce() {
if (videoModelsCache || videoModelsFetching) return;
videoModelsFetching = true;
videoModelsError = null;
const api = new OmniGenApi();
api.getVideoModels().then(
(res) => {
videoModelsFetching = false;
if (res.success && res.models?.length) {
videoModelsCache = res.models.filter((m) => m.is_disabled !== true);
} else {
videoModelsError = "No video models returned from API";
console.warn("[OmniGen] Video models response:", res);
toast.error(OMNI_MODELS_OUTAGE_MESSAGE);
}
notifyVideoListeners();
},
(err) => {
videoModelsFetching = false;
videoModelsError = err?.message ?? "Failed to fetch video models";
console.error("[OmniGen] Failed to fetch video models:", err);
toast.error(OMNI_MODELS_OUTAGE_MESSAGE);
notifyVideoListeners();
},
);
}
// ── Hooks ────────────────────────────────────────────────────────────────
export function useOmniGenImageModels(): {
models: OmniGenImageModelInfo[];
isLoading: boolean;
error: string | null;
} {
const [models, setModels] = useState<OmniGenImageModelInfo[]>(
imageModelsCache ?? [],
);
const [isLoading, setIsLoading] = useState(!imageModelsCache);
const [error, setError] = useState<string | null>(imageModelsError);
useEffect(() => {
if (imageModelsCache) {
setModels(imageModelsCache);
setIsLoading(false);
setError(null);
return;
}
const onReady = () => {
setIsLoading(false);
if (imageModelsCache) {
setModels(imageModelsCache);
setError(null);
} else {
setError(imageModelsError);
}
};
imageModelsListeners.push(onReady);
fetchImageModelsOnce();
return () => {
imageModelsListeners = imageModelsListeners.filter(
(cb) => cb !== onReady,
);
};
}, []);
return { models, isLoading, error };
}
export function useOmniGenVideoModels(): {
models: OmniGenVideoModelInfo[];
isLoading: boolean;
error: string | null;
} {
const [models, setModels] = useState<OmniGenVideoModelInfo[]>(
videoModelsCache ?? [],
);
const [isLoading, setIsLoading] = useState(!videoModelsCache);
const [error, setError] = useState<string | null>(videoModelsError);
useEffect(() => {
if (videoModelsCache) {
setModels(videoModelsCache);
setIsLoading(false);
setError(null);
return;
}
const onReady = () => {
setIsLoading(false);
if (videoModelsCache) {
setModels(videoModelsCache);
setError(null);
} else {
setError(videoModelsError);
}
};
videoModelsListeners.push(onReady);
fetchVideoModelsOnce();
return () => {
videoModelsListeners = videoModelsListeners.filter(
(cb) => cb !== onReady,
);
};
}, []);
return { models, isLoading, error };
}
// ── Display name helper ──────────────────────────────────────────────────
// The actual name map lives in `@storyteller/model-list` so the gallery cards,
// task queue, and lightbox all resolve names from a single source of truth.
// The API-provided `fullName` (when present) still wins over the static map.
export function getModelDisplayName(
modelId: string,
fullName?: string | null,
): string {
if (fullName) return fullName;
return getCanonicalModelDisplayName(modelId);
}
// ── Description / info helpers ─────────────────────────────────────────────
// Manual fallbacks so we can show a tagline (and a longer info blurb) even when
// the API doesn't return one yet for a given model. The API value always wins.
const MODEL_DESCRIPTIONS: Record<string, string> = {
// ── Image models ──
flux_1_dev: "Open-weight model with rich detail",
flux_1_schnell: "Fastest FLUX for quick drafts",
flux_pro_1p1: "Pro-grade quality and prompt accuracy",
flux_pro_1p1_ultra: "Ultra high-resolution FLUX output",
gpt_image_1: "OpenAI's original image model",
gpt_image_1p5: "OpenAI imagery with reliable text",
gpt_image_2: "4K images with crisp text rendering",
midjourney_7: "Signature artistic, stylized imagery",
midjourney_7_niji: "Anime and illustration styles",
midjourney_8: "Midjourney's latest flagship model",
nano_banana: "Fast, versatile editing and generation",
nano_banana_2: "Pro quality at Flash speed",
nano_banana_pro: "Google's flagship image model",
seedream_4: "High-fidelity photorealistic generation",
seedream_4p5: "ByteDance's next-gen 4K model",
seedream_5_lite: "Lightweight, fast visual reasoning",
// ── Video models ── (seedance_2p0 intentionally omitted)
grok_video: "Stylized video generation by xAI",
grok_imagine_video: "Versatile video styles by xAI",
grok_imagine_video_1p5: "Image-to-video styles by xAI",
kling_1p6_pro: "Smooth, coherent motion",
kling_2p1_pro: "Sharper realism and detail",
kling_2p1_master: "Top-fidelity cinematic motion",
kling_2p5_turbo_pro: "Fast, high-quality generation",
kling_2p6_pro: "Refined motion and prompt control",
kling_3p0_standard: "Next-gen temporal consistency",
kling_3p0_pro: "Kling's flagship cinematic video",
seedance_1p0_lite: "Fast, lightweight video clips",
seedance_1p5_pro: "Keyframes with synced audio",
happy_horse_1p0: "Expressive motion from a frame",
sora_2: "Realistic video with synced audio",
sora_2_pro: "Sora's highest-fidelity tier",
veo_2: "Coherent, high-quality motion",
veo_3: "Realistic video with native audio",
veo_3_fast: "Faster Veo 3 with audio",
veo_3p1: "Latest Veo with finer control",
veo_3p1_fast: "Speed-tuned Veo 3.1",
// ── Edit / VFX ──
switch_x: "Swap or relight backgrounds",
};
const MODEL_INFOS: Record<string, string> = {
// Longer blurbs surfaced behind the (i) info icon. Optional per model.
// nano_banana_pro:
// "Google's flagship image model. Generates up to 4K, supports image references for editing, and batches up to 4 images at once.",
// gpt_image_2:
// "OpenAI's image model with industry-leading text rendering. Emulated resolutions up to 4K and quality presets (High / Medium / Low).",
};
/** Short tagline shown under the model name.
*
* Precedence: the API value always wins; the manual map is only a fallback for
* when the API hasn't returned a value (field absent / null / empty). Exactly
* one source is ever used — never both. Because this is derived from the model
* object (which only exists after the single atomic models fetch resolves), a
* row never renders with the manual value and then swaps to the API one — so
* there's no flicker, including before the API has returned. */
export function getModelDescription(
modelId: string,
apiDescription?: string | null,
): string {
if (apiDescription) return apiDescription;
return MODEL_DESCRIPTIONS[modelId] ?? "";
}
/** Longer info blurb for the (i) icon. Same precedence/no-flicker contract as
* getModelDescription: API value wins, manual map is the fallback, only one is
* ever used. Empty string means "no info icon for this model". */
export function getModelInfo(modelId: string, apiInfo?: string | null): string {
if (apiInfo) return apiInfo;
return MODEL_INFOS[modelId] ?? "";
}
// ── Creator icon helper ──────────────────────────────────────────────────
const MODEL_CREATOR_ICON_MAP: Record<string, string> = {
flux: "blackforestlabs",
nano_banana: "google",
gpt_image: "openai",
midjourney: "midjourney",
seedream: "bytedance",
seedance: "bytedance",
kling: "kling",
sora: "openai",
veo: "google",
grok: "grok",
happy_horse: "alibaba",
// Beeble SwitchX (background change) has no provider icon — use the ArtCraft
// mark since it's surfaced as an ArtCraft feature.
switch_x: "artcraft",
};
const ICON_FILES: Record<string, string> = {
blackforestlabs: "blackforestlabs.svg",
artcraft: "artcraft.svg",
openai: "openai.svg",
midjourney: "midjourney.svg",
bytedance: "bytedance.svg",
kling: "kling.svg",
google: "google.svg",
grok: "grok.svg",
alibaba: "alibaba.svg",
};
export function getModelCreatorIconPath(modelId: string): string {
const basePath = "/images/services";
for (const [prefix, creator] of Object.entries(MODEL_CREATOR_ICON_MAP)) {
if (modelId.startsWith(prefix)) {
const file = ICON_FILES[creator] ?? "generic.svg";
return `${basePath}/${file}`;
}
}
return `${basePath}/generic.svg`;
}
@@ -5,6 +5,8 @@ import { GoogleOAuthProvider } from "@react-oauth/google";
import App from "./app/app";
import { StorytellerApiHostStore, UsersApi } from "@storyteller/api";
import { captureLandingContext, getReferrer } from "@storyteller/common";
import { setOmniGenErrorNotifier } from "@storyteller/omni-gen";
import { toast } from "./components/toast/toast";
const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID;
@@ -28,6 +30,9 @@ if (import.meta.env.DEV) {
}
}
// Surface omni model/generation outages through this app's toast component.
setOmniGenErrorNotifier((message) => toast.error(message));
// Persist landing context (referral username, landing URL, referrer) to apex-
// domain cookies so attribution survives the getartcraft.com →
// app.getartcraft.com hop. First visit wins.
@@ -52,11 +52,13 @@ import {
} from "../../lib/resolve-model-setting";
import {
useOmniGenImageModels,
getModelCreatorIconPath,
OMNI_GENERATE_OUTAGE_MESSAGE,
} from "@storyteller/omni-gen";
import {
getCreatorIconPathForModelId,
getModelDescription,
getModelInfo,
OMNI_GENERATE_OUTAGE_MESSAGE,
} from "../../lib/omni-gen-hooks";
} from "@storyteller/model-list";
import { toast } from "../../components/toast/toast";
import { useSignupCta } from "../../components/signup-cta-modal";
import { useInsufficientCredits } from "../../components/insufficient-credits-modal";
@@ -83,7 +85,7 @@ function buildModelPopoverItems(
info: getModelInfo(model.model, model.extra_info) || undefined,
icon: (
<img
src={getModelCreatorIconPath(model.model)}
src={getCreatorIconPathForModelId(model.model)}
alt={`${model.model} logo`}
className="h-4 w-4 icon-auto-contrast"
/>
@@ -638,7 +640,7 @@ export default function CreateImage() {
richList
triggerIcon={
<img
src={getModelCreatorIconPath(selectedModel?.model ?? "")}
src={getCreatorIconPathForModelId(selectedModel?.model ?? "")}
alt=""
className="h-4 w-4 icon-auto-contrast"
/>
@@ -59,11 +59,13 @@ import {
} from "../../lib/resolve-model-setting";
import {
useOmniGenVideoModels,
getModelCreatorIconPath,
OMNI_GENERATE_OUTAGE_MESSAGE,
} from "@storyteller/omni-gen";
import {
getCreatorIconPathForModelId,
getModelDescription,
getModelInfo,
OMNI_GENERATE_OUTAGE_MESSAGE,
} from "../../lib/omni-gen-hooks";
} from "@storyteller/model-list";
import { useSignupCta } from "../../components/signup-cta-modal";
import { useInsufficientCredits } from "../../components/insufficient-credits-modal";
import { toast } from "../../components/toast/toast";
@@ -153,7 +155,7 @@ function buildModelPopoverItems(
info: getModelInfo(model.model, model.extra_info) || undefined,
icon: (
<img
src={getModelCreatorIconPath(model.model)}
src={getCreatorIconPathForModelId(model.model)}
alt={`${model.model} logo`}
className="h-4 w-4 icon-auto-contrast"
/>
@@ -167,7 +169,7 @@ function buildModelPopoverItems(
disabled: true,
icon: (
<img
src={getModelCreatorIconPath(id)}
src={getCreatorIconPathForModelId(id)}
alt={`${id} logo`}
className="h-5 w-5 icon-auto-contrast"
/>
@@ -1398,7 +1400,7 @@ export default function CreateVideo() {
richList
triggerIcon={
<img
src={getModelCreatorIconPath(selectedModel?.model ?? "")}
src={getCreatorIconPathForModelId(selectedModel?.model ?? "")}
alt=""
className="h-4 w-4 icon-auto-contrast"
/>
@@ -232,7 +232,7 @@ function PageSceneEditor() {
// that output so the user lands in a working starting point. Without a
// `?output=`, Stage3DBody's cold-sync handles the default letterbox by
// reading the selected model's defaultAspectRatio (now 16:9 for the
// InstructiveEdit-tagged models that populate STAGE_3D_PAGE_MODEL_LIST).
// InstructiveEdit-tagged models that populate the Stage3D page model list).
usePromptPrefillFromOutput(imageToken);
const navigateToImageTo3D = useCallback(() => {
@@ -13,7 +13,7 @@
//
// Aspect ratio is intentionally not restored: Stage3DBody's cold-sync
// applies the selected model's defaultAspectRatio (16:9 for the
// InstructiveEdit-tagged models that populate STAGE_3D_PAGE_MODEL_LIST),
// InstructiveEdit-tagged models that populate the Stage3D page model list),
// which matches the common case. Prompts rendered at other aspects lose
// that nuance on prefill — acceptable for a "starting point" seed.
//
@@ -46,15 +46,18 @@
{
"path": "../../libs/components/upload-modal/tsconfig.lib.json"
},
{
"path": "../../libs/components/moodboard/tsconfig.lib.json"
},
{
"path": "../../libs/components/pagedraw/tsconfig.lib.json"
},
{
"path": "../../libs/components/moodboard/tsconfig.lib.json"
},
{
"path": "../../libs/components/slider-v2/tsconfig.lib.json"
},
{
"path": "../../libs/omni-gen/tsconfig.lib.json"
},
{
"path": "../../libs/components/pricing-modal/tsconfig.lib.json"
},
+6 -3
View File
@@ -11,15 +11,18 @@
{
"path": "../../libs/components/upload-modal"
},
{
"path": "../../libs/components/moodboard"
},
{
"path": "../../libs/components/pagedraw"
},
{
"path": "../../libs/components/moodboard"
},
{
"path": "../../libs/components/slider-v2"
},
{
"path": "../../libs/omni-gen"
},
{
"path": "../../libs/components/pricing-modal"
},
@@ -1,7 +1,7 @@
import { memo } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCircleExclamation, faXmark } from "@fortawesome/pro-solid-svg-icons";
import { getModelCreatorIconPath } from "../../lib/omni-gen-hooks";
import { getCreatorIconPathForModelId } from "@storyteller/model-list";
export interface FailedCardProps {
id: string;
@@ -22,7 +22,7 @@ export const FailedCard = memo(function FailedCard({
modelLabel,
onDismiss,
}: FailedCardProps) {
const iconPath = modelId ? getModelCreatorIconPath(modelId) : null;
const iconPath = modelId ? getCreatorIconPathForModelId(modelId) : null;
return (
<div className="relative aspect-square w-full overflow-hidden rounded-lg bg-red-500/10">
<div className="flex h-full flex-col items-center justify-center gap-2 px-4 sm:px-6">
@@ -16,9 +16,9 @@ import { Tooltip } from "@storyteller/ui-tooltip";
import { toast } from "../toast/toast";
import { downloadMediaFile } from "../../lib/download-media";
import {
getModelCreatorIconPath,
getCreatorIconPathForModelId,
getModelDisplayName,
} from "../../lib/omni-gen-hooks";
} from "@storyteller/model-list";
import {
applyMakeVideoFromImage,
applyRecreateFromMediaToken,
@@ -191,7 +191,7 @@ export const GalleryCard = memo(function GalleryCard({
? getModelDisplayName(item.modelId)
: null;
const modelIconPath = item.modelId
? getModelCreatorIconPath(item.modelId)
? getCreatorIconPathForModelId(item.modelId)
: null;
const mediaIcon =
@@ -1,7 +1,7 @@
import { memo } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSpinnerThird } from "@fortawesome/pro-solid-svg-icons";
import { getModelCreatorIconPath } from "../../lib/omni-gen-hooks";
import { getCreatorIconPathForModelId } from "@storyteller/model-list";
export interface PendingCardProps {
id: string;
@@ -41,7 +41,7 @@ export const PendingCard = memo(function PendingCard({
? formatTimeLeft(estimatedTimeLeftMs)
: null;
const iconPath = getModelCreatorIconPath(modelId);
const iconPath = getCreatorIconPathForModelId(modelId);
return (
<div className="relative aspect-square w-full overflow-hidden rounded-lg bg-white/[0.03]">
@@ -23,6 +23,7 @@ import { Button } from "@storyteller/ui-button";
import {
getProviderDisplayName,
getModelDisplayName,
getCreatorIconPathForModelId,
findModelByKey,
} from "@storyteller/model-list";
import { CloseButton } from "@storyteller/ui-close-button";
@@ -30,7 +31,6 @@ import dayjs from "dayjs";
import { ActionReminderModal } from "@storyteller/ui-action-reminder-modal";
import { Lightbox } from "../lightbox/lightbox";
import { showToast } from "../toast/toast";
import { getModelCreatorIconPath } from "../../lib/omni-gen-hooks";
import { getMediaThumbnail, THUMBNAIL_SIZES } from "@storyteller/common";
import { twMerge } from "tailwind-merge";
@@ -219,7 +219,7 @@ const InProgressCard = ({
: null;
const isSeedance2 = task.modelType === "seedance_2p0";
const modelIconPath = task.modelType
? getModelCreatorIconPath(task.modelType)
? getCreatorIconPathForModelId(task.modelType)
: null;
return (
@@ -5,6 +5,8 @@ import { GoogleOAuthProvider } from "@react-oauth/google";
import App from "./app/app";
import { StorytellerApiHostStore, UsersApi } from "@storyteller/api";
import { captureLandingContext, getReferrer } from "@storyteller/common";
import { setOmniGenErrorNotifier } from "@storyteller/omni-gen";
import { toast } from "./components/toast/toast";
const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID;
@@ -25,6 +27,9 @@ if (import.meta.env.DEV) {
}
}
// Surface omni model/generation outages through this app's toast component.
setOmniGenErrorNotifier((message) => toast.error(message));
// Persist landing context (referral username, landing URL, referrer) to apex-
// domain cookies so attribution survives the getartcraft.com →
// app.getartcraft.com hop. First visit wins.
@@ -27,10 +27,8 @@ import { GenerationCountPicker } from "./components/GenerationCountPicker";
import { ResolutionPicker } from "./components/ResolutionPicker";
import { QualityPicker } from "./components/QualityPicker";
import { useImageCostEstimate } from "../../lib/cost-estimate-api";
import {
useOmniGenImageModels,
getModelCreatorIconPath,
} from "../../lib/omni-gen-hooks";
import { useOmniGenImageModels } from "@storyteller/omni-gen";
import { getCreatorIconPathForModelId } from "@storyteller/model-list";
// ── Constants ────────────────────────────────────────────────────────────
@@ -51,7 +49,7 @@ function buildModelPopoverItems(
selected: model.model === selectedId,
icon: (
<img
src={getModelCreatorIconPath(model.model)}
src={getCreatorIconPathForModelId(model.model)}
alt={`${model.model} logo`}
className="h-4 w-4 icon-auto-contrast"
/>
@@ -414,7 +412,7 @@ export default function CreateImage() {
showIconsInList
triggerIcon={
<img
src={getModelCreatorIconPath(selectedModel?.model ?? "")}
src={getCreatorIconPathForModelId(selectedModel?.model ?? "")}
alt=""
className="h-4 w-4 icon-auto-contrast"
/>
@@ -45,10 +45,8 @@ import {
} from "../create-image/components/AspectRatioIcon";
import { GenerationCountPicker } from "../create-image/components/GenerationCountPicker";
import { useVideoCostEstimate } from "../../lib/cost-estimate-api";
import {
useOmniGenVideoModels,
getModelCreatorIconPath,
} from "../../lib/omni-gen-hooks";
import { useOmniGenVideoModels } from "@storyteller/omni-gen";
import { getCreatorIconPathForModelId } from "@storyteller/model-list";
// ── Constants ────────────────────────────────────────────────────────────
@@ -110,7 +108,7 @@ function buildModelPopoverItems(
selected: model.model === selectedId,
icon: (
<img
src={getModelCreatorIconPath(model.model)}
src={getCreatorIconPathForModelId(model.model)}
alt={`${model.model} logo`}
className="h-4 w-4 icon-auto-contrast"
/>
@@ -972,7 +970,7 @@ export default function CreateVideo() {
showIconsInList
triggerIcon={
<img
src={getModelCreatorIconPath(selectedModel?.model ?? "")}
src={getCreatorIconPathForModelId(selectedModel?.model ?? "")}
alt=""
className="h-4 w-4 icon-auto-contrast"
/>
@@ -49,6 +49,9 @@
{
"path": "../../libs/components/gallery-modal/tsconfig.lib.json"
},
{
"path": "../../libs/omni-gen/tsconfig.lib.json"
},
{
"path": "../../libs/components/switch/tsconfig.lib.json"
},
@@ -64,15 +67,15 @@
{
"path": "../../libs/components/gravatar/tsconfig.lib.json"
},
{
"path": "../../libs/model-list/tsconfig.lib.json"
},
{
"path": "../../libs/components/loading-spinner/tsconfig.lib.json"
},
{
"path": "../../libs/components/tooltip/tsconfig.lib.json"
},
{
"path": "../../libs/model-list/tsconfig.lib.json"
},
{
"path": "../../libs/components/popover/tsconfig.lib.json"
},
+6 -3
View File
@@ -14,6 +14,9 @@
{
"path": "../../libs/components/gallery-modal"
},
{
"path": "../../libs/omni-gen"
},
{
"path": "../../libs/components/switch"
},
@@ -29,15 +32,15 @@
{
"path": "../../libs/components/gravatar"
},
{
"path": "../../libs/model-list"
},
{
"path": "../../libs/components/loading-spinner"
},
{
"path": "../../libs/components/tooltip"
},
{
"path": "../../libs/model-list"
},
{
"path": "../../libs/components/popover"
},
@@ -1 +0,0 @@
{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.es2022.d.ts","../../node_modules/typescript/lib/lib.es2023.d.ts","../../node_modules/typescript/lib/lib.es2024.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../node_modules/typescript/lib/lib.es2023.collection.d.ts","../../node_modules/typescript/lib/lib.es2023.intl.d.ts","../../node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts","../../node_modules/typescript/lib/lib.es2024.collection.d.ts","../../node_modules/typescript/lib/lib.es2024.object.d.ts","../../node_modules/typescript/lib/lib.es2024.promise.d.ts","../../node_modules/typescript/lib/lib.es2024.regexp.d.ts","../../node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2024.string.d.ts","../../node_modules/typescript/lib/lib.esnext.array.d.ts","../../node_modules/typescript/lib/lib.esnext.collection.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/typescript/lib/lib.esnext.disposable.d.ts","../../node_modules/typescript/lib/lib.esnext.promise.d.ts","../../node_modules/typescript/lib/lib.esnext.decorators.d.ts","../../node_modules/typescript/lib/lib.esnext.iterator.d.ts","../../node_modules/typescript/lib/lib.esnext.float16.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../node_modules/@remix-run/node/dist/globals.d.ts","../../node_modules/@types/cookie/index.d.ts","../../node_modules/@remix-run/server-runtime/dist/crypto.d.ts","../../node_modules/@remix-run/server-runtime/dist/cookies.d.ts","../../node_modules/@remix-run/server-runtime/dLine truncated
@@ -7,8 +7,6 @@ import {
Model,
ImageModel,
VideoModel,
VIDEO_MODELS,
IMAGE_MODELS,
SPLAT_MODELS,
OBJECT_3D_MODELS,
} from "@storyteller/model-list";
@@ -45,9 +43,9 @@ const cubeIcon = <FontAwesomeIcon icon={faCube} className="h-4 w-4" />;
* the InstructiveEdit tag, etc.). Those flags do not exist in the storyteller-web
* omni backend, so this subsetting is maintained here in the frontend overlay.
*
* Each builder is a pure function over a model list, so it can run against either
* the static overlay (the `*_PAGE_MODEL_LIST` constants below) or the live,
* backend-reconciled list from `useModelsStore` (the `use*PageModelList` hooks).
* Each builder is a pure function over a model list. React components consume
* them through the `use*PageModelList` hooks, which run them against the live,
* backend-reconciled list from `useModelsStore`.
*/
export const buildTextToImagePageList = (imageModels: ImageModel[]): ModelList =>
@@ -95,29 +93,10 @@ export const buildImageToVideoPageList = (videoModels: VideoModel[]): ModelList
);
// ---------------------------------------------------------------------------
// Backward-compatible static constants (computed from the frontend overlay).
// Prefer the `use*PageModelList` hooks in React components so the dropdowns
// reflect the backend-reconciled model set.
// Static constants for the 3D pages. Splat/3D-object models are not served by
// the omni backend, so these stay overlay-driven (no hook counterparts).
// ---------------------------------------------------------------------------
export const TEXT_TO_IMAGE_PAGE_MODEL_LIST: ModelList =
buildTextToImagePageList(IMAGE_MODELS);
export const CANVAS_2D_PAGE_MODEL_LIST: ModelList =
buildCanvas2dPageList(IMAGE_MODELS);
export const STAGE_3D_PAGE_MODEL_LIST: ModelList =
buildStage3dPageList(IMAGE_MODELS);
export const IMAGE_EDITOR_PAGE_MODEL_LIST: ModelList =
buildImageEditorPageList(IMAGE_MODELS);
export const IMAGE_TO_VIDEO_PAGE_MODEL_LIST: ModelList =
buildImageToVideoPageList(VIDEO_MODELS);
export const ANGLES_PAGE_MODEL_LIST: ModelList =
buildAnglesPageList(IMAGE_MODELS);
export const IMAGE_TO_3D_WORLD_PAGE_MODEL_LIST: ModelList = buildItems(
SPLAT_MODELS as Model[],
cubeIcon,
+1 -1
View File
@@ -8,6 +8,7 @@ export * from "./lib/classes/metadata/ModelCreator.js";
export * from "./lib/classes/metadata/ModelCreatorIcons.js";
export * from "./lib/classes/metadata/ModelCreatorIconForId.js";
export * from "./lib/classes/metadata/ModelMapping.js";
export * from "./lib/classes/metadata/ModelDescriptions.js";
export * from "./lib/classes/metadata/PromptFormatters.js";
export * from "./lib/classes/metadata/ModelTag.js";
export * from "./lib/classes/metadata/SizeOption.js";
@@ -22,5 +23,4 @@ export * from "./lib/classes/SplatModel.js";
export * from "./lib/lists/SplatModels.js";
export * from "./lib/classes/Object3DModel.js";
export * from "./lib/lists/Object3DModels.js";
export * from "./lib/loader/modelReconciliation.js";
export * from "./lib/loader/buildModelsFromListing.js";
@@ -6,8 +6,8 @@ import {
import { ALL_MODELS_LIST } from "../../lists/AllModels.js";
// Fallback prefix → creator map for model ids that aren't in ALL_MODELS_LIST
// (legacy / API-only ids). Mirrors the webapp's omni-gen icon mapping.
const MODEL_ID_PREFIX_CREATORS: Array<[string, ModelCreator]> = [
// (legacy / API-only ids). Shared with the model-list loader's creator guess.
export const MODEL_ID_PREFIX_CREATORS: Array<[string, ModelCreator]> = [
["flux", ModelCreator.BlackForestLabs],
["nano_banana", ModelCreator.Google],
["gpt_image", ModelCreator.OpenAi],
@@ -19,6 +19,7 @@ const MODEL_ID_PREFIX_CREATORS: Array<[string, ModelCreator]> = [
["veo", ModelCreator.Google],
["grok", ModelCreator.Grok],
["happy_horse", ModelCreator.Alibaba],
["qwen", ModelCreator.Alibaba],
// Beeble SwitchX (background change) has no provider icon — use the ArtCraft
// mark since it's surfaced as an ArtCraft feature.
["switch_x", ModelCreator.ArtCraft],
@@ -0,0 +1,76 @@
// Manual fallbacks so we can show a tagline (and a longer info blurb) even when
// the API doesn't return one yet for a given model. The API value always wins.
const MODEL_DESCRIPTIONS: Record<string, string> = {
// ── Image models ──
flux_1_dev: "Open-weight model with rich detail",
flux_1_schnell: "Fastest FLUX for quick drafts",
flux_pro_1p1: "Pro-grade quality and prompt accuracy",
flux_pro_1p1_ultra: "Ultra high-resolution FLUX output",
gpt_image_1: "OpenAI's original image model",
gpt_image_1p5: "OpenAI imagery with reliable text",
gpt_image_2: "4K images with crisp text rendering",
midjourney_7: "Signature artistic, stylized imagery",
midjourney_7_niji: "Anime and illustration styles",
midjourney_8: "Midjourney's latest flagship model",
nano_banana: "Fast, versatile editing and generation",
nano_banana_2: "Pro quality at Flash speed",
nano_banana_pro: "Google's flagship image model",
seedream_4: "High-fidelity photorealistic generation",
seedream_4p5: "ByteDance's next-gen 4K model",
seedream_5_lite: "Lightweight, fast visual reasoning",
// ── Video models ── (seedance_2p0 intentionally omitted)
grok_video: "Stylized video generation by xAI",
grok_imagine_video: "Versatile video styles by xAI",
grok_imagine_video_1p5: "Image-to-video styles by xAI",
kling_1p6_pro: "Smooth, coherent motion",
kling_2p1_pro: "Sharper realism and detail",
kling_2p1_master: "Top-fidelity cinematic motion",
kling_2p5_turbo_pro: "Fast, high-quality generation",
kling_2p6_pro: "Refined motion and prompt control",
kling_3p0_standard: "Next-gen temporal consistency",
kling_3p0_pro: "Kling's flagship cinematic video",
seedance_1p0_lite: "Fast, lightweight video clips",
seedance_1p5_pro: "Keyframes with synced audio",
happy_horse_1p0: "Expressive motion from a frame",
sora_2: "Realistic video with synced audio",
sora_2_pro: "Sora's highest-fidelity tier",
veo_2: "Coherent, high-quality motion",
veo_3: "Realistic video with native audio",
veo_3_fast: "Faster Veo 3 with audio",
veo_3p1: "Latest Veo with finer control",
veo_3p1_fast: "Speed-tuned Veo 3.1",
// ── Edit / VFX ──
switch_x: "Swap or relight backgrounds",
};
const MODEL_INFOS: Record<string, string> = {
// Longer blurbs surfaced behind the (i) info icon. Optional per model.
// nano_banana_pro:
// "Google's flagship image model. Generates up to 4K, supports image references for editing, and batches up to 4 images at once.",
// gpt_image_2:
// "OpenAI's image model with industry-leading text rendering. Emulated resolutions up to 4K and quality presets (High / Medium / Low).",
};
/** Short tagline shown under the model name.
*
* Precedence: the API value always wins; the manual map is only a fallback for
* when the API hasn't returned a value (field absent / null / empty). Exactly
* one source is ever used, never both. Because this is derived from the model
* object (which only exists after the single atomic models fetch resolves), a
* row never renders with the manual value and then swaps to the API one, so
* there's no flicker, including before the API has returned. */
export function getModelDescription(
modelId: string,
apiDescription?: string | null,
): string {
if (apiDescription) return apiDescription;
return MODEL_DESCRIPTIONS[modelId] ?? "";
}
/** Longer info blurb for the (i) icon. Same precedence/no-flicker contract as
* getModelDescription: API value wins, manual map is the fallback, only one is
* ever used. Empty string means "no info icon for this model". */
export function getModelInfo(modelId: string, apiInfo?: string | null): string {
if (apiInfo) return apiInfo;
return MODEL_INFOS[modelId] ?? "";
}
@@ -163,8 +163,14 @@ export const getModelCreatorName = (modelType: string): string | null => {
}
};
// Convert model type string to human-readable display name
export const getModelDisplayName = (modelType: string): string => {
// Convert model type string to human-readable display name. An API-provided
// full name (when present) wins over the static map.
export const getModelDisplayName = (
modelType: string,
fullName?: string | null,
): string => {
if (fullName) return fullName;
const displayNames: Record<string, string> = {
// Grok
grok_image: "Grok Image",
@@ -22,11 +22,7 @@ import { SizeIconOption, SizeOption } from "../classes/metadata/SizeOption.js";
import { CommonAspectRatio } from "../classes/properties/CommonAspectRatio.js";
import { CommonResolution } from "../classes/properties/CommonResolution.js";
import { CommonQuality } from "../classes/properties/CommonQuality.js";
import {
BACKEND_TO_TAURI_IMAGE_ID,
BACKEND_TO_TAURI_VIDEO_ID,
modelCreatorFromBackend,
} from "./modelReconciliation.js";
import { MODEL_ID_PREFIX_CREATORS } from "../classes/metadata/ModelCreatorIconForId.js";
// ── Structural shapes of the backend listing (subset we read) ──────────────
@@ -77,15 +73,13 @@ export const buildImageModelsFromListing = (
overlay: ImageModel[],
listing: ListingImageModel[],
offeredModelIds: string[] = [],
): ImageModel[] =>
build(overlay, listing, offeredModelIds, BACKEND_TO_TAURI_IMAGE_ID, mergedImageModel);
): ImageModel[] => build(overlay, listing, offeredModelIds, mergedImageModel);
export const buildVideoModelsFromListing = (
overlay: VideoModel[],
listing: ListingVideoModel[],
offeredModelIds: string[] = [],
): VideoModel[] =>
build(overlay, listing, offeredModelIds, BACKEND_TO_TAURI_VIDEO_ID, mergedVideoModel);
): VideoModel[] => build(overlay, listing, offeredModelIds, mergedVideoModel);
// ── Core assembly ──────────────────────────────────────────────────────────
@@ -104,21 +98,20 @@ const build = <T extends { tauriId: string }, L extends ListingModelBase>(
overlay: T[],
listing: L[],
offeredModelIds: string[],
alias: Record<string, string>,
merge: (m: L, tauriId: string, overlayEntry: T | undefined) => T,
): T[] => {
const toTauriId = (backendId: string) => alias[backendId] ?? backendId;
// Backend model ids and overlay `tauriId`s share the same identifier space
// (the 2026-07 id migration retired all aliasing).
const overlayByTauriId = new Map(overlay.map((m) => [m.tauriId, m]));
const knownTauriIds = new Set(listing.map((m) => toTauriId(m.model)));
const offeredTauriIds = new Set(offeredModelIds.map(toTauriId));
const knownTauriIds = new Set(listing.map((m) => m.model));
const offeredTauriIds = new Set(offeredModelIds);
// Capability lookup — prefer the enabled detail entry when duplicated.
const detailsByTauriId = new Map<string, L>();
for (const m of listing) {
const tauriId = toTauriId(m.model);
const existing = detailsByTauriId.get(tauriId);
const existing = detailsByTauriId.get(m.model);
if (existing === undefined || existing.is_disabled === true) {
detailsByTauriId.set(tauriId, m);
detailsByTauriId.set(m.model, m);
}
}
@@ -126,7 +119,7 @@ const build = <T extends { tauriId: string }, L extends ListingModelBase>(
const seenTauriIds = new Set<string>();
// Backend details order drives ordering.
for (const m of listing) {
const tauriId = toTauriId(m.model);
const tauriId = m.model;
if (seenTauriIds.has(tauriId)) continue;
const overlayEntry = overlayByTauriId.get(tauriId);
@@ -141,12 +134,11 @@ const build = <T extends { tauriId: string }, L extends ListingModelBase>(
}
// Offered models with no detail entry at all (unusual, but the publish
// switch wins): surface minimally.
for (const backendId of offeredModelIds) {
const tauriId = toTauriId(backendId);
for (const tauriId of offeredModelIds) {
if (seenTauriIds.has(tauriId)) continue;
seenTauriIds.add(tauriId);
result.push(
merge({ model: backendId } as L, tauriId, overlayByTauriId.get(tauriId)),
merge({ model: tauriId } as L, tauriId, overlayByTauriId.get(tauriId)),
);
}
// Append frontend-only models the backend has never heard of.
@@ -366,21 +358,6 @@ const resolutionLabel = (value: string): string => {
// Guess a creator from the API's `model_creator`, then the overlay, then the
// model-id prefix, then ArtCraft.
const CREATOR_BY_PREFIX: Array<[string, ModelCreator]> = [
["flux", ModelCreator.BlackForestLabs],
["nano_banana", ModelCreator.Google],
["gpt_image", ModelCreator.OpenAi],
["seedream", ModelCreator.Bytedance],
["seedance", ModelCreator.Bytedance],
["kling", ModelCreator.Kling],
["sora", ModelCreator.OpenAi],
["veo", ModelCreator.Google],
["grok", ModelCreator.Grok],
["happy_horse", ModelCreator.Alibaba],
["midjourney", ModelCreator.Midjourney],
["qwen", ModelCreator.Alibaba],
];
const creatorFor = (
raw: string | null | undefined,
modelId: string,
@@ -389,8 +366,37 @@ const creatorFor = (
const mapped = modelCreatorFromBackend(raw ?? undefined);
if (mapped) return mapped;
if (overlayCreator) return overlayCreator;
for (const [prefix, creator] of CREATOR_BY_PREFIX) {
for (const [prefix, creator] of MODEL_ID_PREFIX_CREATORS) {
if (modelId.startsWith(prefix)) return creator;
}
return ModelCreator.ArtCraft;
};
/** Backend `model_creator` snake_case string -> frontend `ModelCreator` enum. */
const modelCreatorFromBackend = (raw?: string): ModelCreator | undefined => {
switch (raw) {
case "alibaba": return ModelCreator.Alibaba;
case "artcraft": return ModelCreator.ArtCraft;
case "black_forest_labs": return ModelCreator.BlackForestLabs;
case "bytedance": return ModelCreator.Bytedance;
case "fal": return ModelCreator.Fal;
case "google": return ModelCreator.Google;
case "grok": return ModelCreator.Grok;
case "hailuo": return ModelCreator.Hailuo;
case "higgsfield": return ModelCreator.Higgsfield;
case "kling": return ModelCreator.Kling;
case "krea": return ModelCreator.Krea;
case "midjourney": return ModelCreator.Midjourney;
case "open_ai": return ModelCreator.OpenAi;
case "open_art": return ModelCreator.OpenArt;
case "recraft": return ModelCreator.Recraft;
case "replicate": return ModelCreator.Replicate;
case "runway": return ModelCreator.Runway;
case "stability": return ModelCreator.Stability;
case "tencent": return ModelCreator.Tencent;
case "tensor_art": return ModelCreator.TensorArt;
case "vidu": return ModelCreator.Vidu;
case "world_labs": return ModelCreator.WorldLabs;
default: return undefined;
}
};
@@ -1,96 +0,0 @@
// Reconciles the frontend model OVERLAY (the hand-maintained `IMAGE_MODELS` /
// `VIDEO_MODELS`, which carry all the UI/product metadata + page-capability flags)
// against the backend omni listing (`ListImageModels` / `ListVideoModels`).
//
// The backend is authoritative for WHICH models are offered; the overlay is
// authoritative for the metadata the backend doesn't have (selectorName, badges,
// tags, canTextToImage/canEditImages/canEditAngles, sizeOptions, durations, and
// the frontend-only models switch_x / inpaint / angle / kontext).
//
// This module is intentionally PURE (no tauri-api import) so `model-list` stays
// free of a circular dependency. The async loader that calls the Tauri commands
// lives in `tauri-api` and feeds `knownBackendIds` / `offeredBackendIds` here.
import { ImageModel } from "../classes/ImageModel.js";
import { VideoModel } from "../classes/VideoModel.js";
import { ModelCreator } from "../classes/metadata/ModelCreator.js";
/**
* Backend omni model id (the `CommonImageModel` serde string) -> frontend `tauriId`.
*
* MIGRATION (2026-07): RETIRED. The overlay `tauriId`s now use the
* storyteller-web omni identifiers directly, and the Tauri generate commands
* accept them, so no aliasing remains. Do not add entries — fix ids at the
* source instead. (Kept exported until the reconcile helpers are deleted.)
* See external/reports/2026-07/storyteller-web-omni-vs-tauri-model-differences.md.
*/
export const BACKEND_TO_TAURI_IMAGE_ID: Record<string, string> = {};
export const BACKEND_TO_TAURI_VIDEO_ID: Record<string, string> = {};
/** Backend `model_creator` snake_case string -> frontend `ModelCreator` enum. */
export const modelCreatorFromBackend = (raw?: string): ModelCreator | undefined => {
switch (raw) {
case "alibaba": return ModelCreator.Alibaba;
case "artcraft": return ModelCreator.ArtCraft;
case "black_forest_labs": return ModelCreator.BlackForestLabs;
case "bytedance": return ModelCreator.Bytedance;
case "fal": return ModelCreator.Fal;
case "google": return ModelCreator.Google;
case "grok": return ModelCreator.Grok;
case "hailuo": return ModelCreator.Hailuo;
case "higgsfield": return ModelCreator.Higgsfield;
case "kling": return ModelCreator.Kling;
case "krea": return ModelCreator.Krea;
case "midjourney": return ModelCreator.Midjourney;
case "open_ai": return ModelCreator.OpenAi;
case "open_art": return ModelCreator.OpenArt;
case "recraft": return ModelCreator.Recraft;
case "replicate": return ModelCreator.Replicate;
case "runway": return ModelCreator.Runway;
case "stability": return ModelCreator.Stability;
case "tencent": return ModelCreator.Tencent;
case "tensor_art": return ModelCreator.TensorArt;
case "vidu": return ModelCreator.Vidu;
case "world_labs": return ModelCreator.WorldLabs;
default: return undefined;
}
};
const toTauriIds = (backendIds: string[], alias: Record<string, string>): Set<string> =>
new Set(backendIds.map((id) => alias[id] ?? id));
/**
* Membership is BACKEND-DRIVEN, mirroring the web apps' `omni-gen-hooks` (which
* render `res.models.filter((m) => m.is_disabled !== true)`):
*
* - Keep an overlay model when the backend returns it ENABLED.
* - Drop it when the backend KNOWS the model but has it disabled (`is_disabled`).
* - Keep it when the backend has never heard of it — a frontend-only model like
* `switch_x` / inpaint / angles that has no omni counterpart.
*
* The overlay only supplies the UI metadata the backend lacks (selectorName,
* badges, tags, capability flags); the backend response decides what appears.
*/
const reconcile = <T extends { tauriId: string }>(
overlay: T[],
knownBackendIds: string[],
enabledBackendIds: string[],
alias: Record<string, string>,
): T[] => {
const known = toTauriIds(knownBackendIds, alias);
const enabled = toTauriIds(enabledBackendIds, alias);
return overlay.filter((m) => enabled.has(m.tauriId) || !known.has(m.tauriId));
};
export const reconcileImageModels = (
overlay: ImageModel[],
knownBackendIds: string[],
enabledBackendIds: string[],
): ImageModel[] => reconcile(overlay, knownBackendIds, enabledBackendIds, BACKEND_TO_TAURI_IMAGE_ID);
export const reconcileVideoModels = (
overlay: VideoModel[],
knownBackendIds: string[],
enabledBackendIds: string[],
): VideoModel[] => reconcile(overlay, knownBackendIds, enabledBackendIds, BACKEND_TO_TAURI_VIDEO_ID);
+12
View File
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
+7
View File
@@ -0,0 +1,7 @@
# @storyteller/omni-gen
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test @storyteller/omni-gen` to execute the unit tests via [Vitest](https://vitest.dev/).
+17
View File
@@ -0,0 +1,17 @@
{
"name": "@storyteller/omni-gen",
"version": "0.0.1",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"development": "./src/index.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
}
}
+1
View File
@@ -0,0 +1 @@
export * from "./lib/omni-gen-hooks.js";
@@ -5,6 +5,27 @@ import type {
OmniGenVideoModelInfo,
} from "@storyteller/api";
// Shown when the OmniGen service is unavailable (e.g. returns 5xx). Separate
// copy for the two failure points so the user knows which step failed.
export const OMNI_MODELS_OUTAGE_MESSAGE =
"Couldn't load models - the generation service may be down. Try again shortly.";
export const OMNI_GENERATE_OUTAGE_MESSAGE =
"Couldn't start generation - the service is temporarily unavailable. Try again shortly.";
// ── Error notifier ───────────────────────────────────────────────────────
// User-facing outage notifications are injected by the host app (each app has
// its own toast component) via `setOmniGenErrorNotifier` at startup, before the
// first hook mounts. Defaults to a no-op; the console logging below always runs
// so failures are never silent.
export type OmniGenErrorNotifier = (message: string) => void;
let errorNotifier: OmniGenErrorNotifier = () => {};
export const setOmniGenErrorNotifier = (notifier: OmniGenErrorNotifier): void => {
errorNotifier = notifier;
};
// ── Singleton caches (fetch once per session) ────────────────────────────
let imageModelsCache: OmniGenImageModelInfo[] | null = null;
@@ -40,6 +61,7 @@ function fetchImageModelsOnce() {
} else {
imageModelsError = "No image models returned from API";
console.warn("[OmniGen] Image models response:", res);
errorNotifier(OMNI_MODELS_OUTAGE_MESSAGE);
}
notifyImageListeners();
},
@@ -47,6 +69,7 @@ function fetchImageModelsOnce() {
imageModelsFetching = false;
imageModelsError = err?.message ?? "Failed to fetch image models";
console.error("[OmniGen] Failed to fetch image models:", err);
errorNotifier(OMNI_MODELS_OUTAGE_MESSAGE);
notifyImageListeners();
},
);
@@ -65,6 +88,7 @@ function fetchVideoModelsOnce() {
} else {
videoModelsError = "No video models returned from API";
console.warn("[OmniGen] Video models response:", res);
errorNotifier(OMNI_MODELS_OUTAGE_MESSAGE);
}
notifyVideoListeners();
},
@@ -72,6 +96,7 @@ function fetchVideoModelsOnce() {
videoModelsFetching = false;
videoModelsError = err?.message ?? "Failed to fetch video models";
console.error("[OmniGen] Failed to fetch video models:", err);
errorNotifier(OMNI_MODELS_OUTAGE_MESSAGE);
notifyVideoListeners();
},
);
@@ -112,7 +137,9 @@ export function useOmniGenImageModels(): {
fetchImageModelsOnce();
return () => {
imageModelsListeners = imageModelsListeners.filter((cb) => cb !== onReady);
imageModelsListeners = imageModelsListeners.filter(
(cb) => cb !== onReady,
);
};
}, []);
@@ -152,88 +179,11 @@ export function useOmniGenVideoModels(): {
fetchVideoModelsOnce();
return () => {
videoModelsListeners = videoModelsListeners.filter((cb) => cb !== onReady);
videoModelsListeners = videoModelsListeners.filter(
(cb) => cb !== onReady,
);
};
}, []);
return { models, isLoading, error };
}
// ── Display name helper ──────────────────────────────────────────────────
const MODEL_DISPLAY_NAMES: Record<string, string> = {
// Image models
flux_1_dev: "Flux 1 Dev",
flux_1_schnell: "Flux 1 Schnell",
flux_pro_1p1: "Flux Pro 1.1",
flux_pro_1p1_ultra: "Flux Pro 1.1 Ultra",
gpt_image_1p5: "GPT Image 1.5",
nano_banana: "Nano Banana",
nano_banana_2: "Nano Banana 2",
nano_banana_pro: "Nano Banana Pro",
seedream_4: "Seedream 4",
seedream_4p5: "Seedream 4.5",
seedream_5_lite: "Seedream 5 Lite",
// Video models
grok_video: "Grok Video",
kling_1p6_pro: "Kling 1.6 Pro",
kling_2p1_pro: "Kling 2.1 Pro",
kling_2p1_master: "Kling 2.1 Master",
kling_2p5_turbo_pro: "Kling 2.5 Turbo Pro",
kling_2p6_pro: "Kling 2.6 Pro",
kling_3p0_standard: "Kling 3.0 Standard",
kling_3p0_pro: "Kling 3.0 Pro",
seedance_1p0_lite: "Seedance 1.0 Lite",
seedance_1p5_pro: "Seedance 1.5 Pro",
seedance_2p0: "Seedance 2.0",
happy_horse_1p0: "Happy Horse 1.0",
sora_2: "Sora 2",
sora_2_pro: "Sora 2 Pro",
veo_2: "Google Veo 2",
veo_3: "Google Veo 3",
veo_3_fast: "Google Veo 3 Fast",
veo_3p1: "Google Veo 3.1",
veo_3p1_fast: "Google Veo 3.1 Fast",
};
export function getModelDisplayName(modelId: string, fullName?: string | null): string {
if (fullName) return fullName;
return MODEL_DISPLAY_NAMES[modelId] ?? modelId;
}
// ── Creator icon helper ──────────────────────────────────────────────────
const MODEL_CREATOR_ICON_MAP: Record<string, string> = {
flux: "blackforestlabs",
nano_banana: "google",
gpt_image: "openai",
seedream: "bytedance",
seedance: "bytedance",
kling: "kling",
sora: "openai",
veo: "google",
grok: "grok",
happy_horse: "alibaba",
};
const ICON_FILES: Record<string, string> = {
blackforestlabs: "blackforestlabs.svg",
artcraft: "artcraft.svg",
openai: "openai.svg",
bytedance: "bytedance.svg",
kling: "kling.svg",
google: "google.svg",
grok: "grok.svg",
alibaba: "alibaba.svg",
};
export function getModelCreatorIconPath(modelId: string): string {
const basePath = "/images/services";
for (const [prefix, creator] of Object.entries(MODEL_CREATOR_ICON_MAP)) {
if (modelId.startsWith(prefix)) {
const file = ICON_FILES[creator] ?? "generic.svg";
return `${basePath}/${file}`;
}
}
return `${basePath}/generic.svg`;
}
+16
View File
@@ -0,0 +1,16 @@
{
"files": [],
"include": [],
"references": [
{
"path": "../api"
},
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json"
}
+50
View File
@@ -0,0 +1,50 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts",
"vite/client"
],
"rootDir": "src",
"jsx": "react-jsx",
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo"
},
"exclude": [
"out-tsc",
"dist",
"**/*.spec.ts",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx"
],
"include": [
"src/**/*.js",
"src/**/*.jsx",
"src/**/*.ts",
"src/**/*.tsx"
],
"references": [
{
"path": "../api/tsconfig.lib.json"
}
]
}
+34
View File
@@ -0,0 +1,34 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./out-tsc/vitest",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
],
"jsx": "react-jsx"
},
"include": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
+51
View File
@@ -0,0 +1,51 @@
/// <reference types='vitest' />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import dts from 'vite-plugin-dts';
import * as path from 'path';
import { isExternal } from '../shared-vite-config';
export default defineConfig(() => ({
root: __dirname,
cacheDir: '../../node_modules/.vite/libs/omni-gen',
plugins: [react(), dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') })],
// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: './dist',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
},
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: 'src/index.ts',
name: '@storyteller/omni-gen',
fileName: 'index',
// Change this to the formats you want to support.
// Don't forget to update your package.json as well.
formats: ['es' as const]
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: isExternal
},
},
test: {
watch: false,
globals: true,
passWithNoTests: true,
environment: 'jsdom',
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: './test-output/vitest/coverage',
provider: 'v8' as const,
}
},
}));
+387 -2228
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -212,6 +212,9 @@
},
{
"path": "./libs/components/moodboard"
},
{
"path": "./libs/omni-gen"
}
]
}