Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Image results: Make it 3D (quick) opens Image to 3D on Idol 3D's Quick look with the picture in

Claude46f676290d81
diff --git a/src/components/model3d/model3d-studio.tsx b/src/components/model3d/model3d-studio.tsx
index ce7acbf1..41bbe6cc 100644
--- a/src/components/model3d/model3d-studio.tsx
+++ b/src/components/model3d/model3d-studio.tsx
@@ -24,16 +24,16 @@ import {
MODEL3D_FILM_FEATURE,
MODEL3D_MODES,
MODELS_3D,
- RIG_MODEL,
SIDE_LABELS,
SIDES_HINT,
VIEW_SIDES,
idolPhotoFor,
isIdol,
+ MAKE_3D_HINT,
model3dBlocker,
+ readModel3dLink,
model3dFor,
model3dRequest,
- modeOf,
type IdolQuality,
type Model3dInput,
type Model3dMode,
@@ -70,19 +70,29 @@ const HINTS: Record<Model3dMode, string> = {
};
/**
- * A link's ?model= (from ⌘K) picks that model, its mode and its engine; ?mode= picks a mode; ?model=meshy-rigging
- * (rigging works on a finished model) says where Rig & animate is. Under its own Suspense: it reads the URL.
+ * A link's ?model= (from ⌘K, or an image result's Make it 3D) picks that model, its mode and its engine; ?mode= picks a
+ * mode; ?model=meshy-rigging (rigging works on a finished model) says where Rig & animate is; ?quality= sets Idol 3D's
+ * look and ?image= fills the photo slot (readModel3dLink). Under its own Suspense: it reads the URL.
*/
-function UrlModel({ onModel, onMode, onRig }: { onModel: (mode: Model3dMode, engine: Engine, id: string) => void; onMode: (mode: Model3dMode) => void; onRig: () => void }) {
+function UrlModel({
+ onModel,
+ onMode,
+ onRig,
+ onImage,
+}: {
+ onModel: (mode: Model3dMode, engine: Engine, id: string, quality?: IdolQuality) => void;
+ onMode: (mode: Model3dMode) => void;
+ onRig: () => void;
+ onImage: (url: string, photo: boolean) => void;
+}) {
const params = useSearchParams();
- const id = params.get("model");
- const mode = params.get("mode");
useEffect(() => {
- const found = id ? modeOf(id) : null;
- if (found && id) onModel(found.mode, found.engine, id);
- else if (id === RIG_MODEL) onRig();
- else if (MODEL3D_MODES.some((m) => m.id === mode)) onMode(mode as Model3dMode);
- }, [id, mode, onModel, onMode, onRig]);
+ const link = readModel3dLink(params);
+ if (link.model) onModel(link.model.mode, link.model.engine, link.model.id, link.quality);
+ else if (link.rig) onRig();
+ else if (link.mode) onMode(link.mode);
+ if (link.image) onImage(link.image, !!link.photo);
+ }, [params, onModel, onMode, onRig, onImage]);
return null;
}
@@ -226,13 +236,24 @@ export function Model3dStudio({ info }: { info: Record<string, Model3dInfo> }) {
const [refine, setRefine] = useState<Hi3dResolution | null>(null);
const showRigHint = useCallback(() => setRigHint(true), []);
const fromUrl = useCallback(
- (m: Model3dMode, e: Engine, id: string) => {
+ (m: Model3dMode, e: Engine, id: string, quality?: IdolQuality) => {
setMode(m);
setPicked((p) => ({ ...p, [`${m}:${e}`]: id }));
+ if (quality && isIdol(id)) setIdolQualities((p) => ({ ...p, [`${m}:${e}`]: quality }));
setEngine(e);
},
[setEngine],
);
+ // A picture handed over in the link (an image result's Make it 3D): in the slot as a result made here, so Idol's photo
+ // crop starts off (the tighter crop suits a generated picture), or on for an upload (?photo=1).
+ const [handed, setHanded] = useState<string | null>(null);
+ const fromImage = useCallback((url: string, asPhoto: boolean) => {
+ const v: SlotValue = { id: "link", ref: url, preview: url, kind: "image", source: asPhoto ? "upload" : "generation" };
+ lastPhoto.current = v;
+ setPhoto(v);
+ setIdolPhoto(asPhoto);
+ setHanded(url);
+ }, []);
// Models switched off in Settings → Models & licences leave the menu, and the pick falls back to one that is on.
const choices = keepOffered(MODELS_3D[mode][engine], (m) => offered(access, m.id, engine));
const wanted = picked[`${mode}:${engine}`];
@@ -282,7 +303,7 @@ export function Model3dStudio({ info }: { info: Record<string, Model3dInfo> }) {
return (
<ToolShell title="Image to 3D" selfHostedOnly>
<Suspense fallback={null}>
- <UrlModel onModel={fromUrl} onMode={setMode} onRig={showRigHint} />
+ <UrlModel onModel={fromUrl} onMode={setMode} onRig={showRigHint} onImage={fromImage} />
</Suspense>
<ToolHero title="Your product, in 3D" subtitle={HINTS[mode]}>
{visitor && <SelfHostNote className="mt-3 max-w-xl">Image to 3D isn&apos;t available here.</SelfHostNote>}
@@ -414,6 +435,11 @@ export function Model3dStudio({ info }: { info: Record<string, Model3dInfo> }) {
</div>
{!idol && (mode === "image" || mode === "multi") && <RefineOption engine={engine} value={refine} onChange={setRefine} openAllowed={refineAllowed} onUseGpu={() => setEngine("open")} />}
{idol && <IdolSettings quality={idolQuality} onQuality={setIdolQuality} photo={idolPhoto} onPhoto={setIdolPhoto} />}
+ {idol && engine === "open" && !!handed && photo?.ref === handed && (
+ <p className="mt-3 rounded-xl bg-brand-faint px-3 py-2 text-[12px] text-brand-text" data-testid="make-3d-hint">
+ {MAKE_3D_HINT}
+ </p>
+ )}
<Button size="lg" className={cn("mt-4 w-full rounded-full", blocker && "bg-muted text-muted-foreground hover:bg-muted")} onClick={go} disabled={create.isPending || visitor}>
{create.isPending ? <Loader2 className="size-4 animate-spin" /> : <Box className="size-4" />} {mode === "splat" ? "Make the splat" : "Make it 3D"}
</Button>
diff --git a/src/components/studio/result-actions.tsx b/src/components/studio/result-actions.tsx
index eba10dd8..c5da8e44 100644
--- a/src/components/studio/result-actions.tsx
+++ b/src/components/studio/result-actions.tsx
@@ -29,6 +29,7 @@ import {
MoreHorizontal,
Pin,
Repeat,
+ Rotate3d,
RotateCcw,
Share2,
SlidersHorizontal,
@@ -72,7 +73,7 @@ import { useShare } from "@/components/share/share-provider";
import { useSkillBuilder } from "@/components/skills/skill-builder-provider";
import { Popover, PopoverAnchor, PopoverContent } from "@/components/ui/popover";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
-import { useCreateGeneration, useEngineMode, useGenerationActions, useSaveElement } from "@/lib/api";
+import { useCreateGeneration, useEngineMode, useGenerationActions, useOpenEngine, useSaveElement } from "@/lib/api";
import { ELEMENT_KINDS, type ElementKind } from "@/lib/catalog/elements";
import { OPERATION_LABELS, type Generation, type OutputFile } from "@/lib/catalog/types";
import { downloadName, userTitle } from "@/lib/library";
@@ -107,6 +108,7 @@ export const ACTION_ICONS: Record<OutputActionId, LucideIcon> = {
"clean-dialogue": AudioLines,
"copy-text": Copy,
"view-3d": Box,
+ "make-3d": Rotate3d,
download: Download,
"download-txt": FileDown,
"download-srt": FileDown,
@@ -411,7 +413,8 @@ export function TileActions({
}) {
const run = useActionRunner(opts);
const engineMode = useEngineMode();
- const list = useMemo(() => outputActions(g, index, { ...ctx, engineMode }), [g, index, ctx, engineMode]);
+ const openEngine = useOpenEngine();
+ const list = useMemo(() => outputActions(g, index, { ...ctx, engineMode, openEngine }), [g, index, ctx, engineMode, openEngine]);
const [saving, setSaving] = useState(false);
const strip = useRef<HTMLDivElement>(null);
const [narrow, setNarrow] = useState(false);
diff --git a/src/components/studio/viewer.tsx b/src/components/studio/viewer.tsx
index 3043d2bb..78a75075 100644
--- a/src/components/studio/viewer.tsx
+++ b/src/components/studio/viewer.tsx
@@ -13,7 +13,7 @@ import { formatCost, timeAgo } from "@/lib/format";
import { PRESETS as GRADE_PRESETS } from "@/lib/grade";
import { trashDaysLeft, userTitle } from "@/lib/library";
import { editOnlyFormat, isLayered, layerInfo, outputActions, type OutputAction } from "@/lib/output-actions";
-import { useEngineMode } from "@/lib/api";
+import { useEngineMode, useOpenEngine } from "@/lib/api";
import { cn } from "@/lib/utils";
import { copyWithToast } from "@/lib/clipboard";
import { CompareSlider } from "./compare-slider";
@@ -167,7 +167,11 @@ export function Viewer({
const [failedVideo, setFailedVideo] = useState<string | null>(null);
const run = useActionRunner({ onReuse: onReuse && ((x) => (onReuse(x), onClose())), onCompare: () => setComparing((v) => !v), onDeleted: onClose });
const engineMode = useEngineMode();
- const list = useMemo(() => outputActions(g, index, { reuse: !!onReuse, compare: !!source, inViewer: true, engineMode }), [g, index, onReuse, source, engineMode]);
+ const openEngine = useOpenEngine();
+ const list = useMemo(
+ () => outputActions(g, index, { reuse: !!onReuse, compare: !!source, inViewer: true, engineMode, openEngine }),
+ [g, index, onReuse, source, engineMode, openEngine],
+ );
// Read the latest values from the key handler without re-subscribing on every render.
const latest = useRef({ list, run, g, index, onPrev, onNext, source });
diff --git a/src/lib/api.ts b/src/lib/api.ts
index adfac68e..9e850d42 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -4,7 +4,7 @@ import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClie
import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
import { toast } from "sonner";
import type { AssistThread, AssistThreadSummary, AssistThreadView } from "./assist";
-import type { OwnerGpuView, TestProvider } from "./connections";
+import { openEngineReady, type OwnerGpuView, type TestProvider } from "./connections";
import type { ElementKind, StudioElement } from "./catalog/elements";
import type { Engine, Generation, GenerationRequest, MediaKind, ReviewStatus } from "./catalog/types";
import {
@@ -29,7 +29,7 @@ import { cursorAfter, filterToSearch, type AssetUse, type FeedFilter, type Folde
import { markRefusalShown, responseError } from "./refusals";
import { postFile } from "./upload";
import type { ShareCreated, ShareInfo, ShareListItem, SharePatch, ShareRequest } from "./share";
-import type { AccessSummary } from "./model-access";
+import { offered, type AccessSummary } from "./model-access";
import { ADD_KEY_HEADER, isCloudProvider, type CloudProvider } from "./your-keys";
import { BILLING_EVENT, BILLING_HEADER, type BillingAction, type BillingRefusalDetail, type HostedBalance } from "./hosted";
@@ -1049,6 +1049,17 @@ export function useEngine(): [Engine, (e: Engine) => void, EngineMode] {
return [mode === "both" ? engine : mode, set, mode];
}
+/**
+ * Whether results offer what runs on the owner's open engine (Make it 3D on a picture: Idol 3D on your GPU): the
+ * install runs open models, ComfyUI is connected (or placeholder results are on), the viewer is the owner, and Idol 3D
+ * is switched on in Settings → Models & licences. False until hydrated and while the status is unknown.
+ */
+export function useOpenEngine(): boolean {
+ const hydrated = useHydrated();
+ const status = useStatus().data;
+ return hydrated && openEngineReady(status) && offered(status?.access, "oss-idol", "open");
+}
+
/** Remember the engine the studios start on, before the mode allows it (an account that just added its own key: Cloud). */
export function preferEngine(e: Engine): void {
try {
diff --git a/src/lib/av/model3d.ts b/src/lib/av/model3d.ts
index 6b26793e..6f569b6a 100644
--- a/src/lib/av/model3d.ts
+++ b/src/lib/av/model3d.ts
@@ -477,3 +477,39 @@ export function retextureRequest(o: { glb: string; prompt?: string; style?: stri
...(o.size && o.size !== "2k" && { params: { extra: { texture_resolution: o.size } } }),
};
}
+
+/**
+ * What an Image to 3D link asks for: ?model= (⌘K, Make it 3D) picks a model, its mode and its engine; ?model=meshy-rigging
+ * says where Rig & animate is; else ?mode= picks a mode. ?quality= is Idol 3D's Best or Quick look, ?image= a picture for
+ * the photo slot (a file Fuobe keeps, or an https link), and ?photo=1 says it is a photo (an upload), so Idol's looser
+ * photo crop starts on; a picture handed over from a result starts with it off (idol-5).
+ */
+/** What Make it 3D (quick) on an image result does: shown in the studio with the picture handed over (never "2 s"). */
+export const MAKE_3D_HINT = "Turns this picture into a 3D splat on your GPU and renders a turning preview. Takes tens of seconds on a consumer GPU.";
+
+export interface Model3dLink {
+ model?: { mode: Model3dMode; engine: Engine; id: string };
+ rig?: boolean;
+ mode?: Model3dMode;
+ quality?: IdolQuality;
+ image?: string;
+ photo?: boolean;
+}
+
+export function readModel3dLink(sp: Pick<URLSearchParams, "get">): Model3dLink {
+ const id = sp.get("model");
+ const mode = sp.get("mode");
+ const found = id ? modeOf(id) : null;
+ const out: Model3dLink = {};
+ if (found && id) out.model = { ...found, id };
+ else if (id === RIG_MODEL) out.rig = true;
+ else if (MODEL3D_MODES.some((m) => m.id === mode)) out.mode = mode as Model3dMode;
+ const quality = sp.get("quality");
+ if (quality === "best" || quality === "quick") out.quality = quality;
+ const image = sp.get("image");
+ if (image && /^(\/api\/files\/|https:\/\/)/.test(image) && image.length <= 2048) {
+ out.image = image;
+ out.photo = sp.get("photo") === "1";
+ }
+ return out;
+}
diff --git a/src/lib/connections.ts b/src/lib/connections.ts
index 7eea9313..f2a14c9f 100644
--- a/src/lib/connections.ts
+++ b/src/lib/connections.ts
@@ -195,6 +195,16 @@ export function connectedEngines(s: ConnectionState): { cloud: boolean; open: bo
return { cloud: CLOUD_PROVIDERS.some((p) => s.providers[p]?.configured), open: !!s.providers.comfyui?.configured };
}
+/**
+ * The open engine can run here for whoever is looking: the owner's install runs open models (Engine mode open or both),
+ * and ComfyUI is connected (on a server or the owner's computer) or placeholder results are on. A guest or an account
+ * (`viewer`) gets no 3D yet, so actions that need the owner's open engine (Make it 3D) stay off for them. Unknown: off.
+ */
+export function openEngineReady(s: (ConnectionState & { viewer?: unknown }) | undefined): boolean {
+ if (!s || s.viewer || s.engineMode === "cloud") return false;
+ return s.demoMode === "on" || !!s.providers.comfyui?.configured || !!s.ownerGpu;
+}
+
/** Nothing this install's engine mode uses is connected, so a run asks to connect one (or makes a placeholder, for a tour). */
export function nothingConnected(s: ConnectionState): boolean {
const c = connectedEngines(s);
diff --git a/src/lib/output-actions.ts b/src/lib/output-actions.ts
index 03fd7ac3..87d45488 100644
--- a/src/lib/output-actions.ts
+++ b/src/lib/output-actions.ts
@@ -44,6 +44,7 @@ export type OutputActionId =
| "clean-dialogue"
| "copy-text"
| "view-3d"
+ | "make-3d"
| "download"
| "download-txt"
| "download-srt"
@@ -90,10 +91,20 @@ export interface ActionContext {
* (a server render, a share page): as "both".
*/
engineMode?: "both" | "open" | "cloud";
+ /**
+ * The open engine can run here: Engine mode is open or both and ComfyUI is connected (or placeholder results are on),
+ * for the owner (openEngineReady in src/lib/connections.ts). Make it 3D (quick) needs it: Idol 3D runs on your GPU.
+ */
+ openEngine?: boolean;
}
const q = (url: string) => encodeURIComponent(url);
+/** Make it 3D (quick) on a picture: Image to 3D → Splat on Idol 3D's Quick look, the picture in the slot (idol-5). */
+export function make3dHref(url: string, photo = false): string {
+ return `/image-to-3d?mode=splat&model=oss-idol&quality=quick&image=${q(url)}${photo ? "&photo=1" : ""}`;
+}
+
/** Every action for output `index` of `g`, in display order. */
export function outputActions(g: Generation, index: number, ctx: ActionContext = {}): OutputAction[] {
const o = g.outputs[index];
@@ -128,6 +139,9 @@ export function outputActions(g: Generation, index: number, ctx: ActionContext =
// A picture drawn from a layout (or one fal's MOSS-Image planned itself) reopens as boxes in the Image studio.
if (editableLayout(g, index)) link("edit-layout", "Edit layout", editLayoutHref(g, index));
link("genjutsu", "Animate with Genjutsu", `/genjutsu?mode=motion&image=${q(o.url)}`);
+ // Idol 3D runs on your GPU only (fal's Idol is a choice of its own in Image to 3D): hidden where the open engine
+ // can't run. An upload is likely a photo, so it opens with the looser photo crop on.
+ if (ctx.openEngine && ctx.engineMode !== "cloud") link("make-3d", "Make it 3D (quick)", make3dHref(o.url, g.feature === "upload"));
out.push({ id: "save-character", label: "Save as character", placement: "menu" });
break;
case "video": {
diff --git a/tests/make-3d.test.ts b/tests/make-3d.test.ts
new file mode 100644
index 00000000..7678ff39
--- /dev/null
+++ b/tests/make-3d.test.ts
@@ -0,0 +1,154 @@
+import { describe, expect, it } from "vitest";
+import type { Generation } from "@/lib/catalog/types";
+import { make3dHref, nextSteps, outputActions } from "@/lib/output-actions";
+import { MAKE_3D_HINT, idolPhotoFor, readModel3dLink } from "@/lib/av/model3d";
+import { openEngineReady } from "@/lib/connections";
+
+/**
+ * Make it 3D (quick) on image results (idol-5, docs/research/idol-9.md §8, §9): a menu action that opens Image to 3D →
+ * Splat on Idol 3D's Quick look with the picture in the slot, shown only where the open engine runs; the studio's link
+ * parsing; and when results count the open engine as ready.
+ */
+
+let n = 0;
+function gen(p: Partial<Generation> = {}): Generation {
+ n++;
+ return {
+ id: `g${n}`,
+ batchId: null,
+ feature: "image",
+ presetId: null,
+ modelId: "nano-banana-pro",
+ engine: "cloud",
+ provider: "fal",
+ op: "t2i",
+ kind: "image",
+ status: "succeeded",
+ progress: 1,
+ message: null,
+ prompt: "a fox",
+ request: { feature: "image", modelId: "nano-banana-pro", prompt: "a fox" },
+ outputs: [{ url: `/api/files/outputs/d/${n}.png`, kind: "image" }],
+ error: null,
+ costUsd: 0,
+ favorite: false,
+ createdAt: 1000 + n,
+ updatedAt: 1000 + n,
+ completedAt: null,
+ deletedAt: null,
+ folderId: null,
+ ...p,
+ };
+}
+
+const ids = (g: Generation, ctx = {}) => outputActions(g, 0, ctx).map((a) => a.id);
+const make3d = (g: Generation, ctx = {}) => outputActions(g, 0, ctx).find((a) => a.id === "make-3d");
+
+describe("Make it 3D (quick) on a result", () => {
+ it("is a menu action on pictures when the open engine can run, with Idol 3D's Quick look and the picture", () => {
+ const g = gen({ outputs: [{ url: "/api/files/outputs/d/fox 1.png", kind: "image" }] });
+ expect(make3d(g, { openEngine: true })).toEqual({
+ id: "make-3d",
+ label: "Make it 3D (quick)",
+ placement: "menu",
+ href: "/image-to-3d?mode=splat&model=oss-idol&quality=quick&image=%2Fapi%2Ffiles%2Foutputs%2Fd%2Ffox%201.png",
+ });
+ expect(make3d(g, { openEngine: true, engineMode: "open" })).toBeDefined();
+ expect(make3d(g, { openEngine: true, engineMode: "both" })).toBeDefined();
+ });
+
+ it("is hidden without the open engine and on installs that run paid APIs only", () => {
+ const g = gen();
+ expect(make3d(g)).toBeUndefined();
+ expect(make3d(g, { openEngine: false, engineMode: "open" })).toBeUndefined();
+ expect(make3d(g, { openEngine: true, engineMode: "cloud" })).toBeUndefined();
+ });
+
+ it("keeps the other picture actions and their order, and sits after the hand-offs", () => {
+ const g = gen();
+ const without = ids(g, { reuse: true });
+ const withIt = ids(g, { reuse: true, openEngine: true });
+ expect(withIt.filter((id) => id !== "make-3d")).toEqual(without);
+ expect(withIt.indexOf("make-3d")).toBe(withIt.indexOf("genjutsu") + 1);
+ });
+
+ it("never appears on videos, sound, text, 3D models, vector pictures or deleted results", () => {
+ const ctx = { openEngine: true, engineMode: "both" as const };
+ expect(ids(gen({ kind: "video", op: "t2v", outputs: [{ url: "/api/files/a.mp4", kind: "video" }] }), ctx)).not.toContain("make-3d");
+ expect(ids(gen({ kind: "audio", op: "tts", outputs: [{ url: "/api/files/a.mp3", kind: "audio" }] }), ctx)).not.toContain("make-3d");
+ expect(ids(gen({ kind: "text", outputs: [{ url: "/api/files/a.txt", kind: "text", text: "hi" }] }), ctx)).not.toContain("make-3d");
+ expect(ids(gen({ kind: "model3d", outputs: [{ url: "/api/files/a.glb", kind: "model3d" }] }), ctx)).not.toContain("make-3d");
+ expect(ids(gen({ outputs: [{ url: "/api/files/logo.svg", kind: "image", contentType: "image/svg+xml" }] }), ctx)).not.toContain("make-3d");
+ expect(ids(gen({ deletedAt: 5 }), ctx)).not.toContain("make-3d");
+ });
+
+ it("opens an upload with the photo crop on", () => {
+ const up = make3d(gen({ feature: "upload", provider: "local", outputs: [{ url: "/api/files/uploads/p.jpg", kind: "image" }] }), { openEngine: true });
+ expect(up?.href).toBe(make3dHref("/api/files/uploads/p.jpg", true));
+ expect(up?.href).toMatch(/&photo=1$/);
+ });
+
+ it("leaves a picture's next steps as they are", () => {
+ for (const ctx of [{}, { openEngine: true }, { openEngine: true, engineMode: "open" as const }]) {
+ expect(nextSteps(gen(), 0, 3, ctx).map((a) => a.id)).toEqual(["animate", "upscale", "edit"]);
+ }
+ });
+
+ it("says tens of seconds on your GPU, never two", () => {
+ expect(MAKE_3D_HINT).toBe("Turns this picture into a 3D splat on your GPU and renders a turning preview. Takes tens of seconds on a consumer GPU.");
+ expect(MAKE_3D_HINT).not.toMatch(/2 ?s\b|seconds\)/);
+ });
+});
+
+describe("Image to 3D's link (readModel3dLink)", () => {
+ const read = (q: string) => readModel3dLink(new URLSearchParams(q));
+
+ it("reads Make it 3D's link: Idol 3D on the open engine in Splat, Quick look, the picture as a generated one", () => {
+ expect(read(make3dHref("/api/files/outputs/d/x.png").split("?")[1])).toEqual({
+ model: { mode: "splat", engine: "open", id: "oss-idol" },
+ quality: "quick",
+ image: "/api/files/outputs/d/x.png",
+ photo: false,
+ });
+ expect(read(make3dHref("/api/files/uploads/p.jpg", true).split("?")[1])).toMatchObject({ image: "/api/files/uploads/p.jpg", photo: true });
+ });
+
+ it("keeps ⌘K's ?model=, ?mode= and Rig & animate's links as they were", () => {
+ expect(read("model=oss-triposplat")).toEqual({ model: { mode: "splat", engine: "open", id: "oss-triposplat" } });
+ expect(read("model=idol-3d&quality=best")).toEqual({ model: { mode: "splat", engine: "cloud", id: "idol-3d" }, quality: "best" });
+ expect(read("model=meshy-rigging")).toEqual({ rig: true });
+ expect(read("mode=splat")).toEqual({ mode: "splat" });
+ expect(read("mode=nope")).toEqual({});
+ expect(read("model=nope&mode=text")).toEqual({ mode: "text" });
+ });
+
+ it("ignores an unknown quality and pictures that aren't a kept file or an https link", () => {
+ expect(read("mode=splat&quality=fast")).toEqual({ mode: "splat" });
+ for (const bad of ["javascript:alert(1)", "data:image/png;base64,AAAA", "http://example.com/a.png", "/etc/passwd", `/api/files/${"a".repeat(3000)}`]) {
+ expect(read(`image=${encodeURIComponent(bad)}`).image).toBeUndefined();
+ }
+ expect(read(`image=${encodeURIComponent("https://cdn.example.com/a.png")}`).image).toBe("https://cdn.example.com/a.png");
+ });
+
+ it("a handed-over result starts the photo crop off, an upload on (the studio's slot value)", () => {
+ expect(idolPhotoFor({ ref: "/api/files/x.png", source: "generation" }, null)).toBe(false);
+ expect(idolPhotoFor({ ref: "/api/files/x.png", source: "upload" }, null)).toBe(true);
+ });
+});
+
+describe("openEngineReady", () => {
+ const s = (p: Partial<Parameters<typeof openEngineReady>[0] & object> = {}) => ({ providers: {}, engineMode: "both" as const, ...p });
+ it("needs open models in Engine mode and ComfyUI connected, the owner's computer, or placeholder results", () => {
+ expect(openEngineReady(undefined)).toBe(false);
+ expect(openEngineReady(s())).toBe(false);
+ expect(openEngineReady(s({ providers: { comfyui: { configured: true } } }))).toBe(true);
+ expect(openEngineReady(s({ engineMode: "open", providers: { comfyui: { configured: true } } }))).toBe(true);
+ expect(openEngineReady(s({ demoMode: "on" }))).toBe(true);
+ expect(openEngineReady(s({ ownerGpu: { mode: "computer", online: false } }))).toBe(true);
+ });
+ it("is off on installs that run paid APIs only, and for guests and accounts", () => {
+ expect(openEngineReady(s({ engineMode: "cloud", providers: { comfyui: { configured: true } }, demoMode: "on" }))).toBe(false);
+ expect(openEngineReady(s({ providers: { comfyui: { configured: true } }, viewer: { kind: "account" } }))).toBe(false);
+ expect(openEngineReady(s({ demoMode: "on", viewer: { kind: "guest" } }))).toBe(false);
+ });
+});