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.

Moodboards: curated sets from the built-in list with Higgsfield's live previews on top

Claude2c9aeb2774f6
diff --git a/src/components/moodboards/cards.tsx b/src/components/moodboards/cards.tsx
index 6aadd640..dad2d636 100644
--- a/src/components/moodboards/cards.tsx
+++ b/src/components/moodboards/cards.tsx
@@ -5,15 +5,25 @@ import type { MoodboardStatus } from "@/lib/catalog/palettes";
import { cn } from "@/lib/utils";
import { STATUS_LABEL, type CuratedMoodboard, type Moodboard } from "./logic";
-/** A drawn cover for a curated look (no Higgsfield images are hot-linked): its hue, its name. */
-export function CuratedCover({ m, className }: { m: Pick<CuratedMoodboard, "name" | "hue">; className?: string }) {
+/**
+ * A curated look's cover: Higgsfield's preview when its live list loaded (a key is set), otherwise
+ * drawn from the look's hue (no Higgsfield images are hot-linked without a key); its name on top.
+ */
+export function CuratedCover({ m, className }: { m: Pick<CuratedMoodboard, "name" | "hue" | "preview">; className?: string }) {
return (
<span
aria-hidden
className={cn("relative block overflow-hidden", className)}
style={{ background: `radial-gradient(120% 90% at 20% 15%, oklch(0.86 0.09 ${m.hue}), transparent 60%), linear-gradient(160deg, oklch(0.62 0.14 ${(m.hue + 30) % 360}), oklch(0.32 0.08 ${(m.hue + 70) % 360}))` }}
>
- <span className="absolute inset-x-2 bottom-2 font-heading text-[19px] leading-tight text-white drop-shadow-sm">{m.name}</span>
+ {m.preview && (
+ <>
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img src={m.preview} alt="" loading="lazy" className="absolute inset-0 size-full object-cover" />
+ <span className="absolute inset-x-0 bottom-0 h-1/2 bg-gradient-to-t from-black/60 to-transparent" />
+ </>
+ )}
+ {m.name && <span className="absolute inset-x-2 bottom-2 font-heading text-[19px] leading-tight text-white drop-shadow-sm">{m.name}</span>}
</span>
);
}
diff --git a/src/components/moodboards/hooks.ts b/src/components/moodboards/hooks.ts
index 7c23b1ac..024504c0 100644
--- a/src/components/moodboards/hooks.ts
+++ b/src/components/moodboards/hooks.ts
@@ -2,8 +2,24 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useCallback, useMemo } from "react";
+import type { SoulPresetModel } from "@/lib/catalog/higgsfield-presets.generated";
import type { Engine } from "@/lib/catalog/types";
-import type { CuratedMoodboard, Moodboard } from "./logic";
+import { CURATED_SETS, withLive, type CuratedMoodboard, type LivePresets, type Moodboard } from "./logic";
+
+/**
+ * A curated set (Soul 2.0's looks or Soul's styles): the built-in list at once, with Higgsfield's
+ * preview images (and newer presets) once its live list loads with a key. Shares the style
+ * picker's cache (the same request).
+ */
+export function useCuratedSet(source: SoulPresetModel, enabled = true): CuratedMoodboard[] {
+ const live = useQuery({
+ queryKey: ["provider-presets", source],
+ queryFn: async () => (await (await fetch(`/api/providers/higgsfield/presets?source=${source}`)).json()) as LivePresets,
+ staleTime: 60 * 60 * 1000,
+ enabled,
+ });
+ return useMemo(() => withLive(CURATED_SETS[source], live.data, source), [source, live.data]);
+}
async function json<T>(res: Response): Promise<T> {
const body = (await res.json().catch(() => ({}))) as T & { error?: string };
diff --git a/src/components/moodboards/logic.ts b/src/components/moodboards/logic.ts
index 28d56012..fa6a5ca6 100644
--- a/src/components/moodboards/logic.ts
+++ b/src/components/moodboards/logic.ts
@@ -3,7 +3,7 @@
* Higgsfield's limits and exact copy, the status a board shows while its cover job runs, which
* images best represent a board, and the 2×2 collages open-source style models take.
*/
-import { SOUL_CATEGORIES, SOUL_PRESETS, type SoulPresetModel } from "@/lib/catalog/higgsfield-presets.generated";
+import { SOUL_CATEGORIES, SOUL_PRESETS, type SoulPreset, type SoulPresetModel } from "@/lib/catalog/higgsfield-presets.generated";
import { getSoulPreset, hueOf } from "@/lib/catalog/packs";
import { kmeans, suggestName, type MoodboardPick, type MoodboardStatus, type RGB } from "@/lib/catalog/palettes";
import type { Engine, Generation } from "@/lib/catalog/types";
@@ -39,21 +39,52 @@ export interface CuratedMoodboard {
categories?: string[];
/** Whose preset: Soul 2.0's looks (the default) or Soul's styles. */
source?: SoulPresetModel;
+ /** Higgsfield's preview image (only when a Higgsfield key is set; otherwise the cover is drawn). */
+ preview?: string;
}
-/**
- * Soul's 106 styles, the Moodboard panel's second curated set: `style_id` on Soul, the description
- * as words on every other model (the open route's prompt template).
- */
-export const SOUL_STYLES: CuratedMoodboard[] = SOUL_PRESETS.filter((p) => p.model === "soul-v1").map((p) => ({
+const toCurated = (p: SoulPreset): CuratedMoodboard => ({
id: p.id,
name: p.name,
category: p.categories[0] ?? "All presets",
categories: p.categories,
description: p.description,
hue: hueOf(p.id),
- source: "soul-v1",
-}));
+ ...(p.model === "soul-v1" && { source: p.model }),
+});
+
+/**
+ * The curated sets of the Moodboard panel, from the built-in list: Soul 2.0's 33 looks, and Soul's
+ * 106 styles. Each is `style_id` on its own model and its description as words on every other model
+ * (the open route's prompt template).
+ */
+export const CURATED_SETS: Record<SoulPresetModel, CuratedMoodboard[]> = {
+ "soul-v2": SOUL_PRESETS.filter((p) => p.model === "soul-v2").map(toCurated),
+ "soul-v1": SOUL_PRESETS.filter((p) => p.model === "soul-v1").map(toCurated),
+};
+export const SOUL_STYLES = CURATED_SETS["soul-v1"];
+
+/** What GET /api/providers/higgsfield/presets returns (Higgsfield's live list, or the built-in one as `fallback`). */
+export interface LivePresets {
+ items?: { id: string; name: string; preview?: string }[];
+ fallback?: boolean;
+}
+
+/**
+ * A curated set with Higgsfield's live list on top (a Higgsfield key is set and the list loaded):
+ * its preview images, and any preset it has that the built-in list doesn't, at the end.
+ */
+export function withLive(base: CuratedMoodboard[], live: LivePresets | undefined, source: SoulPresetModel): CuratedMoodboard[] {
+ if (!live?.items?.length || live.fallback) return base;
+ const byId = new Map(live.items.map((p) => [p.id, p]));
+ const known = new Set(base.map((b) => b.id));
+ return [
+ ...base.map((b) => (byId.get(b.id)?.preview ? { ...b, preview: byId.get(b.id)!.preview } : b)),
+ ...live.items
+ .filter((p) => !known.has(p.id))
+ .map((p) => ({ id: p.id, name: p.name, category: "All presets", categories: [], description: "", hue: hueOf(p.id), preview: p.preview, ...(source === "soul-v1" && { source }) })),
+ ];
+}
/** The category pills of each curated set ("All presets" first). */
export const CURATED_TABS: Record<SoulPresetModel, string[]> = {
diff --git a/src/components/moodboards/moodboard-panel.tsx b/src/components/moodboards/moodboard-panel.tsx
index d7c6c432..ba8507c6 100644
--- a/src/components/moodboards/moodboard-panel.tsx
+++ b/src/components/moodboards/moodboard-panel.tsx
@@ -10,8 +10,8 @@ import type { MoodboardPick } from "@/lib/catalog/palettes";
import { cn } from "@/lib/utils";
import { BoardCover, CuratedCover, StatusBadge } from "./cards";
import { CreateMoodboardDialog } from "./create-moodboard";
-import { useMoodboards } from "./hooks";
-import { COPY, CURATED_TABS, curatedPick, inCuratedTab, SOUL_STYLES, toPick } from "./logic";
+import { useCuratedSet, useMoodboards } from "./hooks";
+import { COPY, CURATED_TABS, curatedPick, inCuratedTab, toPick } from "./logic";
const SETS = [
["soul-v2", "Soul 2.0"],
@@ -31,14 +31,11 @@ export function MoodboardPanel({ value, onPick, modelId }: { value?: MoodboardPi
const [q, setQ] = useState("");
const [creating, setCreating] = useState(false);
const needle = q.trim().toLowerCase();
+ const looks = useCuratedSet(set, tab === "curated");
const curated = useMemo(
- () =>
- (set === "soul-v1" ? SOUL_STYLES : (data?.curated ?? [])).filter((c) =>
- needle ? `${c.name} ${c.description}`.toLowerCase().includes(needle) : inCuratedTab(c, cat),
- ),
- [data, needle, cat, set],
+ () => looks.filter((c) => (needle ? `${c.name} ${c.description}`.toLowerCase().includes(needle) : inCuratedTab(c, cat))),
+ [looks, needle, cat],
);
- const loadingCurated = isLoading && set === "soul-v2";
const mine = useMemo(() => (data?.items ?? []).filter((m) => !needle || m.name.toLowerCase().includes(needle)), [data, needle]);
const card = "group block w-full min-w-0 rounded-lg text-left outline-none focus-visible:ring-2 focus-visible:ring-ring/50";
@@ -111,14 +108,20 @@ export function MoodboardPanel({ value, onPick, modelId }: { value?: MoodboardPi
)}
</div>
<div className="grid max-h-[46svh] grid-cols-3 gap-1.5 overflow-y-auto sm:max-h-[320px]">
- {loadingCurated
- ? Array.from({ length: 6 }, (_, i) => <Skeleton key={i} className="aspect-[3/4]" />)
- : curated.map((c) => (
- <button key={c.id} type="button" title={c.description} aria-pressed={value?.id === c.id} onClick={() => onPick(value?.id === c.id ? undefined : curatedPick(c))} className={card}>
- <CuratedCover m={c} className={cn("aspect-[3/4] rounded-lg ring-offset-2 ring-offset-background", value?.id === c.id && "ring-2 ring-primary")} />
- </button>
- ))}
- {!loadingCurated && !curated.length && <p className="col-span-3 py-6 text-center text-[13px] text-muted-foreground">No presets match “{q}”</p>}
+ {curated.map((c) => (
+ <button
+ key={c.id}
+ type="button"
+ title={c.description || c.name}
+ aria-label={c.name}
+ aria-pressed={value?.id === c.id}
+ onClick={() => onPick(value?.id === c.id ? undefined : curatedPick(c))}
+ className={card}
+ >
+ <CuratedCover m={c} className={cn("aspect-[3/4] rounded-lg ring-offset-2 ring-offset-background", value?.id === c.id && "ring-2 ring-primary")} />
+ </button>
+ ))}
+ {!curated.length && <p className="col-span-3 py-6 text-center text-[13px] text-muted-foreground">No presets match “{q}”</p>}
</div>
</>
) : (
diff --git a/src/components/moodboards/moodboards-view.tsx b/src/components/moodboards/moodboards-view.tsx
index 70134f92..916b9d4f 100644
--- a/src/components/moodboards/moodboards-view.tsx
+++ b/src/components/moodboards/moodboards-view.tsx
@@ -26,8 +26,8 @@ import { useEngine } from "@/lib/api";
import { cn } from "@/lib/utils";
import { BoardCover, CuratedCover, StatusBadge } from "./cards";
import { CreateMoodboardDialog } from "./create-moodboard";
-import { useMoodboardActions, useMoodboards } from "./hooks";
-import { COPY, CURATED_TABS, MOODBOARD_LIMITS, type Moodboard } from "./logic";
+import { useCuratedSet, useMoodboardActions, useMoodboards } from "./hooks";
+import { COPY, CURATED_TABS, inCuratedTab, MOODBOARD_LIMITS, type Moodboard } from "./logic";
/** ?create=1 opens the Create dialog (links from the Image studio and Home). */
function CreateFromUrl({ onOpen }: { onOpen: () => void }) {
@@ -149,9 +149,10 @@ export function MoodboardsView() {
const [deleting, setDeleting] = useState<Moodboard | null>(null);
const needle = q.trim().toLowerCase();
const mine = useMemo(() => (data?.items ?? []).filter((m) => !needle || m.name.toLowerCase().includes(needle)), [data, needle]);
+ const looks = useCuratedSet("soul-v2", tab === "curated");
const curated = useMemo(
- () => (data?.curated ?? []).filter((c) => (needle ? `${c.name} ${c.description}`.toLowerCase().includes(needle) : cat === "All presets" || c.category === cat)),
- [data, needle, cat],
+ () => looks.filter((c) => (needle ? `${c.name} ${c.description}`.toLowerCase().includes(needle) : inCuratedTab(c, cat))),
+ [looks, needle, cat],
);
return (
@@ -249,17 +250,20 @@ export function MoodboardsView() {
</div>
)}
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-5">
- {isLoading
- ? Array.from({ length: 10 }, (_, i) => <Skeleton key={i} className="aspect-[3/4] rounded-xl" />)
- : curated.map((c) => (
- <Link key={c.id} href={`/image?moodboard=curated:${c.id}`} className="group/cur min-w-0 rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring/50">
- <CuratedCover m={c} className="aspect-[3/4] rounded-xl transition-transform duration-300 group-hover/cur:scale-[1.02]" />
- <p className="mt-1.5 px-0.5 text-[12px] text-muted-foreground">{c.category}</p>
- <p className="line-clamp-2 px-0.5 text-[12.5px]">{c.description}</p>
- </Link>
- ))}
+ {curated.map((c) => (
+ <Link
+ key={c.id}
+ href={`/image?moodboard=curated:${c.id}`}
+ aria-label={`Use ${c.name} in the Image studio${c.description ? ` — ${c.description}` : ""}`}
+ className="group/cur min-w-0 rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
+ >
+ <CuratedCover m={c} className="aspect-[3/4] rounded-xl transition-transform duration-300 group-hover/cur:scale-[1.02]" />
+ <p className="mt-1.5 px-0.5 text-[12px] text-muted-foreground">{c.category}</p>
+ <p className="line-clamp-2 px-0.5 text-[12.5px]">{c.description}</p>
+ </Link>
+ ))}
</div>
- {!isLoading && !curated.length && <p className="py-16 text-center text-[14px] text-muted-foreground">No presets match “{q}”</p>}
+ {!curated.length && <p className="py-16 text-center text-[14px] text-muted-foreground">No presets match “{q}”</p>}
<p className="mt-6 text-[12.5px] text-muted-foreground">
Curated looks are Soul 2.0 presets: Higgsfield Soul 2.0 takes them as its style; other models, including the open-source ones, get each look as a prompt.
</p>
diff --git a/src/server/moodboards.ts b/src/server/moodboards.ts
index dc22166e..9590fb49 100644
--- a/src/server/moodboards.ts
+++ b/src/server/moodboards.ts
@@ -1,9 +1,8 @@
import "server-only";
import { nanoid } from "nanoid";
-import { CURATED_MOODBOARDS, hueOf } from "@/lib/catalog/packs";
import { getTrainingTarget } from "@/lib/catalog/training";
import type { Engine, Generation } from "@/lib/catalog/types";
-import { COVER_PROMPT, MOODBOARD_LIMITS, moodboardStatus, moodboardError, type Moodboard } from "@/components/moodboards/logic";
+import { COVER_PROMPT, CURATED_SETS, MOODBOARD_LIMITS, moodboardStatus, moodboardError, type CuratedMoodboard, type Moodboard } from "@/components/moodboards/logic";
import { db } from "./db";
import { createElement, getElement } from "./elements";
import { createGenerations, getGeneration } from "./generations";
@@ -102,8 +101,8 @@ export function getMoodboard(id: string): Moodboard | null {
}
/** Soul 2.0's 33 built-in looks, for the Curated tab. */
-export function curatedMoodboards() {
- return CURATED_MOODBOARDS.map((p) => ({ id: p.id, name: p.name, category: p.categories[0] ?? "All presets", description: p.description, hue: hueOf(p.id) }));
+export function curatedMoodboards(): CuratedMoodboard[] {
+ return CURATED_SETS["soul-v2"];
}
/** The engine a board is prepared on: the one asked for, unless Settings locks the other. */
diff --git a/tests/image-studios.test.ts b/tests/image-studios.test.ts
index 8de50b0e..28b62502 100644
--- a/tests/image-studios.test.ts
+++ b/tests/image-studios.test.ts
@@ -56,6 +56,7 @@ import {
collageGroups,
colorFeature,
coverCrop,
+ CURATED_SETS,
CURATED_TABS,
curatedPick,
imageProblem,
@@ -65,6 +66,7 @@ import {
representativeOrder,
SOUL_STYLES,
soulPick,
+ withLive,
} from "@/components/moodboards/logic";
// The caps GET /api/palettes sends (src/server/palettes.ts signatureCaps, checked against the catalog in image-studios-api.test.ts).
@@ -286,6 +288,19 @@ describe("moodboards: routing per model", () => {
expect(turbo.request.prompt).toBe(presetPrompt(sunset, "a rooftop party"));
});
+ it("curated sets come from the built-in list, with Higgsfield's live previews (and newer presets) on top", () => {
+ expect(CURATED_SETS["soul-v2"].map((c) => c.id)).toEqual(CURATED_MOODBOARDS.map((p) => p.id));
+ const base = CURATED_SETS["soul-v2"];
+ // No key: the route answers with the built-in list as a fallback — nothing changes.
+ expect(withLive(base, { items: [{ id: base[0].id, name: "General", preview: "https://x/p.jpg" }], fallback: true }, "soul-v2")).toBe(base);
+ const live = withLive(base, { items: [{ id: base[1].id, name: base[1].name, preview: "https://x/1.jpg" }, { id: "new-look", name: "Brand new" }] }, "soul-v2");
+ expect(live).toHaveLength(base.length + 1);
+ expect(live[1].preview).toBe("https://x/1.jpg");
+ expect(live[0].preview).toBeUndefined();
+ expect(live.at(-1)).toMatchObject({ id: "new-look", name: "Brand new", category: "All presets" });
+ expect(curatedPick(withLive(CURATED_SETS["soul-v1"], { items: [{ id: "v1-new", name: "New one" }] }, "soul-v1").at(-1)!).source).toBe("soul-v1");
+ });
+
it("a reused run isn't styled twice (Reuse keeps the composer's chips)", () => {
const once = applySignature(req("oss-z-image-turbo"), { moodboard: curated, palette: PAL }, ctx);
const twice = applySignature({ ...req(once.modelId), prompt: once.request.prompt, inputs: once.request.inputs }, { moodboard: curated, palette: PAL }, ctx);