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.

Marketing fixes from the browser pass

Claudec0e742dcdcec
diff --git a/src/components/ads/ads-home.tsx b/src/components/ads/ads-home.tsx
index c9cac6cc..820e2aff 100644
--- a/src/components/ads/ads-home.tsx
+++ b/src/components/ads/ads-home.tsx
@@ -111,8 +111,8 @@ export function AdsHome() {
</section>
<section className="mt-14">
- <div className="mb-4 flex items-end justify-between gap-3">
- <h2 className="font-heading text-[24px]">Your brands</h2>
+ <div className="mb-4 flex flex-col gap-1 sm:flex-row sm:items-end sm:justify-between sm:gap-3">
+ <h2 className="font-heading text-[24px] whitespace-nowrap">Your brands</h2>
<span className="text-[12px] text-muted-foreground">Every brand gets its own research, products and ads</span>
</div>
{brands.isLoading ? (
diff --git a/src/components/ads/clip-range.tsx b/src/components/ads/clip-range.tsx
index cb9e20cc..d61e7da0 100644
--- a/src/components/ads/clip-range.tsx
+++ b/src/components/ads/clip-range.tsx
@@ -1,7 +1,7 @@
"use client";
import { Play, Scissors } from "lucide-react";
-import { useEffect, useRef } from "react";
+import { useEffect, useRef, useState } from "react";
import { clampClip, initialClip, MULTIPLIER, type ClipRange as Range } from "@/lib/catalog/marketing";
import { cn } from "@/lib/utils";
@@ -12,8 +12,10 @@ const fmt = (s: number) => `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart
* A plain in/out picker for the reference ad: the player, a bar showing the kept part, two time
* fields and "set from the playhead" buttons. (A drop-in for a fuller trimmer later.)
*/
-export function ClipRange({ src, duration, value, onChange, onDuration, className }: { src: string; duration: number | null; value: Range | null; onChange: (r: Range) => void; onDuration: (d: number) => void; className?: string }) {
+export function ClipRange({ src, duration, value, onChange, onDuration, onUnplayable, className }: { src: string; duration: number | null; value: Range | null; onChange: (r: Range) => void; onDuration: (d: number) => void; onUnplayable?: () => void; className?: string }) {
const video = useRef<HTMLVideoElement>(null);
+ const [failed, setFailed] = useState<string | null>(null);
+ const unplayable = failed === src;
const stopAt = useRef<number | null>(null);
useEffect(() => {
const v = video.current;
@@ -49,9 +51,18 @@ export function ClipRange({ src, duration, value, onChange, onDuration, classNam
playsInline
preload="metadata"
onLoadedMetadata={(e) => Number.isFinite(e.currentTarget.duration) && onDuration(e.currentTarget.duration)}
- className="mx-auto max-h-[46vh] w-full rounded-xl bg-black object-contain"
+ onError={() => {
+ setFailed(src);
+ onUnplayable?.();
+ }}
+ className={cn("mx-auto max-h-[46vh] w-full rounded-xl bg-black object-contain", unplayable && "hidden")}
aria-label="Reference ad"
/>
+ {unplayable && (
+ <div className="grid aspect-video place-items-center rounded-xl bg-muted px-6 text-center text-[13px] text-muted-foreground">
+ This browser can&apos;t play this clip&apos;s format, so there&apos;s no preview here. It&apos;s still used as it is — set the in and out points by time.
+ </div>
+ )}
{range && d > 0 && (
<div className="mt-3 space-y-2.5">
<div className="relative h-2 rounded-full bg-muted" aria-hidden>
diff --git a/src/components/ads/creative-grid.tsx b/src/components/ads/creative-grid.tsx
index 474945c7..994df45d 100644
--- a/src/components/ads/creative-grid.tsx
+++ b/src/components/ads/creative-grid.tsx
@@ -130,7 +130,7 @@ export function CreativeGrid({ brand, products, creatives }: { brand: BrandKit;
};
return (
- <section aria-label="Ads">
+ <section aria-label="Ads" className="@container">
{pending > 0 && <p className="mb-3 text-[13px] text-muted-foreground">Generating {pending} ad{pending === 1 ? "" : "s"} — they land in the grid as they render.</p>}
<div className="mb-4 flex flex-wrap items-center gap-2">
<div role="radiogroup" aria-label="Format" className="inline-flex rounded-full bg-muted p-0.5">
@@ -163,7 +163,7 @@ export function CreativeGrid({ brand, products, creatives }: { brand: BrandKit;
{groups.map((g) => (
<div key={g.key} className="mb-8">
{g.title && <h3 className="mb-3 text-[14px] font-semibold">{g.title}</h3>}
- <div className={cn("grid gap-x-3 gap-y-5", ratio === "9:16" ? "grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 xl:grid-cols-6" : "grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5")}>
+ <div className={cn("grid gap-x-3 gap-y-5", ratio === "9:16" ? "grid-cols-2 @xl:grid-cols-3 @4xl:grid-cols-4 @6xl:grid-cols-5" : "grid-cols-2 @2xl:grid-cols-3 @5xl:grid-cols-4 @7xl:grid-cols-5")}>
{g.items.map((c) => (
<CreativeCard key={c.id} c={c} brand={brand} ratio={ratio} product={byId.get(c.productId ?? "")} n={number.get(c.id) ?? 0} onEdit={() => setEditing(c)} />
))}
diff --git a/src/components/ads/multiplier.tsx b/src/components/ads/multiplier.tsx
index 18b49dad..e4169449 100644
--- a/src/components/ads/multiplier.tsx
+++ b/src/components/ads/multiplier.tsx
@@ -13,6 +13,7 @@ import { uploadImages } from "@/components/brand/image-list";
import { fileToSlot, LibraryGrid, type SlotValue } from "@/components/studio/media-slot";
import { initialClip, mentionedImages, MULTIPLIER, MULTIPLIER_MODELS, multiplierResolution, type ClipRange as Range, type MarketingRun, type RunEstimate } from "@/lib/catalog/marketing";
import { formatCost } from "@/lib/format";
+import { probeMedia } from "@/lib/media-probe";
import { cn } from "@/lib/utils";
import { addRuns, send, useEstimate, useStatusFlags } from "@/components/marketing/hooks";
import type { ModelInfo } from "@/components/marketing/model-info";
@@ -198,18 +199,36 @@ export function AdMultiplier({ models }: { models: Record<string, ModelInfo> })
const length = cut ? cut.end - cut.start : 0;
const ready = !!video && !video.uploading && !!video.ref && duration != null && !!cut;
+ // Which reference is current (a late answer about an older clip is ignored), and whether its length is known.
+ const clip = useRef(0);
+ const known = useRef(false);
/** A new reference (a library pick, or an upload that reports its preview first, then its server URL). */
const startVideo = () => {
+ clip.current += 1;
+ known.current = false;
setDuration(null);
setRange(null);
+ return clip.current;
+ };
+ /** The length from the file's own header, for clips this browser can't play (e.g. H.264 without the codec). */
+ const probe = async (source: Blob | string, token: number) => {
+ try {
+ const blob = typeof source === "string" ? await (await fetch(source)).blob() : source;
+ const d = probeMedia(new Uint8Array(await blob.arrayBuffer()))?.duration;
+ if (d && token === clip.current && !known.current) onDuration(d);
+ } catch {
+ // Unknown container: the player is the only other source of the length.
+ }
};
const onFile = (f: File) => {
if (!f.type.startsWith("video/") && !/\.(mp4|mov|webm|m4v)$/i.test(f.name)) return void toast("Video only — drop a clip here");
- startVideo();
+ const token = startVideo();
void fileToSlot(f, setVideo, "video");
+ if (f.size <= 400 * 1024 * 1024) void probe(f, token);
};
const onDuration = (d: number) => {
- const first = duration == null;
+ const first = !known.current;
+ known.current = true;
setDuration(d);
setRange((r) => r ?? initialClip(d));
if (!first) return;
@@ -300,7 +319,10 @@ export function AdMultiplier({ models }: { models: Record<string, ModelInfo> })
<ReferenceDrop onFile={onFile} onPick={(v) => (startVideo(), setVideo(v))} />
) : (
<div className="relative">
- <ClipRange src={video.preview} duration={duration} value={range} onChange={setRange} onDuration={onDuration} />
+ <ClipRange src={video.preview} duration={duration} value={range} onChange={setRange} onDuration={onDuration} onUnplayable={() => {
+ if (!video.uploading && video.ref && !known.current) void probe(video.ref, clip.current);
+ }}
+ />
{video.uploading && (
<p className="mt-2 inline-flex items-center gap-1.5 text-[12px] text-muted-foreground">
<Loader2 className="size-3 animate-spin" /> Uploading…
diff --git a/src/components/marketing/click-to-ad.tsx b/src/components/marketing/click-to-ad.tsx
index 08a8c9e2..2a75bc00 100644
--- a/src/components/marketing/click-to-ad.tsx
+++ b/src/components/marketing/click-to-ad.tsx
@@ -174,7 +174,7 @@ export function ClickToAd({ models }: { models: Record<string, ModelInfo> }) {
<button key={p.id} type="button" onClick={() => choose(p)} aria-pressed={p.id === productId} className={cn("w-28 shrink-0 rounded-xl border p-1.5 text-left outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring", p.id === productId && "border-primary bg-brand-faint")}>
<ProductThumb product={p} className="aspect-square rounded-lg" />
<span className="mt-1 block truncate text-[12px] font-medium">{p.name}</span>
- <span className="block truncate text-[11px] text-muted-foreground">{priceText(p) || `${p.images.length} pictures`}</span>
+ <span className="block truncate text-[11px] text-muted-foreground">{priceText(p) || `${p.images.length} picture${p.images.length === 1 ? "" : "s"}`}</span>
</button>
))}
</div>
@@ -188,7 +188,7 @@ export function ClickToAd({ models }: { models: Record<string, ModelInfo> }) {
<Step n={2} title="Your product kit" hint="Review the details we extracted — edit anything before generating your video." done={!!desc.trim() && picked.length > 0}>
<div className="grid min-w-0 gap-5 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
<div className="min-w-0 space-y-3">
- <p className="text-[12px] font-medium text-muted-foreground">These {Math.min(3, picked.length) || 3} images will be used in your video</p>
+ <p className="text-[12px] font-medium text-muted-foreground">{picked.length === 0 ? "Pick at least one image for your video" : picked.length === 1 ? "This image will be used in your video" : `These ${picked.length} images will be used in your video`}</p>
<ImageList value={picked} onChange={(v) => setPicked(v.slice(0, 5))} max={5} heroLabel="First" size="sm" />
{product.images.filter((u) => !picked.includes(u)).length > 0 && (
<>
diff --git a/src/components/marketing/shell.tsx b/src/components/marketing/shell.tsx
index ce3225ce..09fdc967 100644
--- a/src/components/marketing/shell.tsx
+++ b/src/components/marketing/shell.tsx
@@ -2,6 +2,7 @@
import { Clapperboard, Copy, LayoutTemplate, MousePointerClick, Target } from "lucide-react";
import Link from "next/link";
+import { useEffect, useRef } from "react";
import { SidebarTrigger } from "@/components/ui/sidebar";
import { EngineSwitch } from "@/components/studio/engine-switch";
import { useEngine } from "@/lib/api";
@@ -19,6 +20,14 @@ const TABS: { id: SuiteTab; href: string; label: string; icon: typeof Target }[]
/** The marketing suite's sticky header: title, the four tools as tabs, and the engine switch. */
export function MarketingHeader({ title, active, engine, onEngine, right }: { title: string; active: SuiteTab; engine?: Engine; onEngine?: (e: Engine) => void; right?: React.ReactNode }) {
+ const nav = useRef<HTMLElement>(null);
+ // On a phone the tabs scroll sideways: bring the current one into view.
+ useEffect(() => {
+ const el = nav.current?.querySelector<HTMLElement>('[aria-current="page"]');
+ const box = nav.current;
+ if (!el || !box) return;
+ if (el.offsetLeft + el.offsetWidth > box.scrollLeft + box.clientWidth || el.offsetLeft < box.scrollLeft) box.scrollLeft = el.offsetLeft - 12;
+ }, [active]);
return (
<header className="sticky top-0 z-30 border-b border-transparent bg-background/85 backdrop-blur supports-[backdrop-filter]:bg-background/70">
<div className="flex h-14 min-w-0 items-center gap-2 px-3 sm:px-6">
@@ -29,7 +38,7 @@ export function MarketingHeader({ title, active, engine, onEngine, right }: { ti
{engine && onEngine && <EngineSwitch value={engine} onChange={onEngine} />}
</div>
</div>
- <nav aria-label="Marketing tools" className="scrollbar-none -mb-px flex gap-1 overflow-x-auto px-3 sm:px-6">
+ <nav ref={nav} aria-label="Marketing tools" className="scrollbar-none -mb-px flex gap-1 overflow-x-auto px-3 sm:px-6">
{TABS.map((t) => (
<Link
key={t.id}
diff --git a/src/server/ads.ts b/src/server/ads.ts
index f425fad2..b7dbc803 100644
--- a/src/server/ads.ts
+++ b/src/server/ads.ts
@@ -539,14 +539,30 @@ export function mentionedProducts(text: string, products: Pick<Product, "id" | "
return [...products].sort((a, b) => b.name.length - a.name.length).filter((p) => mentionRe(p.name).test(text)).map((p) => p.id);
}
-/** What to make from a message with no LLM: counts ("4 ads"), @mentions, and the rest as direction. */
+const NUMBER_WORDS: Record<string, number> = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10, twelve: 12, fifteen: 15, twenty: 20 };
+/** "2 ads", "three playful ad variations", "5 new versions": the number, the words between, the noun. */
+const COUNT_RE = new RegExp(`\\b(\\d{1,2}|${Object.keys(NUMBER_WORDS).join("|")})\\s+((?:[a-z'-]+\\s+){0,3}?)(?:new\\s+)?(?:ads?|variations?|versions?|creatives?)(?:\\s+(?:variations?|versions?|creatives?))?\\b`, "i");
+
+/**
+ * What to make from a message with no LLM: the count ("2 playful ads", "three ads"), the
+ * @mentioned products, and the rest as the creative direction ("playful", "with a holiday theme").
+ */
export function offlineProposal(text: string, products: Pick<Product, "id" | "name">[]): { count: number; productIds: string[]; direction: string } | null {
if (!/\b(ads?|make|create|generate|variations?|versions?|more|another|locali[sz]e|change)\b/i.test(text)) return null;
- const count = Math.min(MAX_ADS_PER_PRODUCT, Math.max(1, parseInt(/(\d{1,2})\s*(?:new\s+)?(?:ads?|variations?|versions?|creatives?)/i.exec(text)?.[1] ?? "4", 10)));
- let direction = text;
+ const m = COUNT_RE.exec(text);
+ const n = m ? (NUMBER_WORDS[m[1].toLowerCase()] ?? parseInt(m[1], 10)) : 4;
+ const count = Math.min(MAX_ADS_PER_PRODUCT, Math.max(1, n));
const ids = mentionedProducts(text, products);
- for (const p of products) direction = direction.replace(mentionRe(p.name), p.name);
- direction = direction.replace(/\b(please|can you|could you|make|create|generate|write)\b/gi, " ").replace(/\b\d{1,2}\s*(new\s+)?(ads?|variations?|versions?|creatives?)\b/gi, " ").replace(/\s+/g, " ").trim();
+ // The direction keeps the describing words ("playful") and drops the count, the products and the verbs.
+ let direction = m ? text.replace(m[0], m[2].replace(/\bads?\b/gi, "")) : text;
+ for (const p of [...products].sort((a, b) => b.name.length - a.name.length)) direction = direction.replace(new RegExp(`(?:\\b(?:for|of|with|featuring)\\s+)?${mentionRe(p.name).source}`, "gi"), " ");
+ direction = direction
+ .replace(/\b(please|can you|could you|make|create|generate|write|me|some)\b/gi, " ")
+ .replace(/\bfor (?:my|our|the|this) products?\b/gi, " ")
+ .replace(/\s+([,.!?])/g, "$1")
+ .replace(/^[\s,.:;-]+|[\s,.:;-]+$/g, "")
+ .replace(/\s+/g, " ")
+ .trim();
return { count, productIds: ids, direction };
}
@@ -611,7 +627,7 @@ export async function chat(brandId: string, text: string): Promise<ChatMessage[]
? {
id: nanoid(8),
role: "assistant",
- text: `Here's the plan: ${p.count} ad${p.count === 1 ? "" : "s"} for ${ids.map((id) => products.find((x) => x.id === id)?.name).join(", ")}${p.direction ? `, ${p.direction.charAt(0).toLowerCase()}${p.direction.slice(1)}` : ""}. Create them?`,
+ text: `Here's the plan: ${p.count} ad${p.count === 1 ? "" : "s"}${ids.length > 1 ? " each" : ""} for ${ids.map((id) => products.find((x) => x.id === id)?.name).join(", ")}${p.direction ? ` — ${p.direction.charAt(0).toLowerCase()}${p.direction.slice(1)}` : ""}. Create ${p.count * ids.length === 1 ? "it" : "them"}?`,
at: Date.now(),
proposal: { items: ids.map((productId) => ({ productId, count: p.count })), direction: p.direction || undefined },
}
diff --git a/tests/marketing-api.test.ts b/tests/marketing-api.test.ts
index 8c2e9571..e264abba 100644
--- a/tests/marketing-api.test.ts
+++ b/tests/marketing-api.test.ts
@@ -455,7 +455,11 @@ describe("Ads Studio", () => {
const res = await chatRoute.POST(json("POST", { text: "Make 3 ads for @Night Serum with a holiday theme" }), params({ id: brandId }));
const { messages } = await res.json();
const reply = messages.at(-1);
- expect(reply.proposal).toEqual({ items: [{ productId: products[1].id, count: 3 }], direction: "for Night Serum with a holiday theme" });
+ expect(reply.proposal).toEqual({ items: [{ productId: products[1].id, count: 3 }], direction: "with a holiday theme" });
+ expect(reply.text).toBe("Here's the plan: 3 ads for Night Serum — with a holiday theme. Create them?");
+ expect(ads.offlineProposal("Make 2 playful ads for @Night Serum", products)).toEqual({ count: 2, productIds: [products[1].id], direction: "playful" });
+ expect(ads.offlineProposal("Write five ad variations with different CTAs", products)).toMatchObject({ count: 5, productIds: [], direction: "with different CTAs" });
+ expect(ads.offlineProposal("Generate 4 ads for my product", products)).toMatchObject({ count: 4, direction: "" });
const question = await (await chatRoute.POST(json("POST", { text: "What's our tone?" }), params({ id: brandId }))).json();
expect(question.messages.at(-1).proposal).toBeNull();
const ok = await confirmRoute.POST(json("POST", { messageId: reply.id, engine: "cloud" }), params({ id: brandId }));