caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

192 lines
7.7 KiB
TypeScript

"use client";
import { useState } from "react";
import Link from "next/link";
import { ArrowRight, Loader2, Shuffle, Sparkles } from "lucide-react";
import { SignedIn, SignedOut } from "@/components/auth/clerk-safe";
import { Button } from "@/components/ui/button";
import { Select } from "@/components/ui/select";
import { Textarea } from "@/components/ui/textarea";
import { MAX_TOPIC_CHARS, type GenerateOutput, type ReelResult, validateGenerateRequest } from "@/lib/seo/free-tools/generate";
import { templateOutput } from "@/lib/seo/free-tools/templates";
import { OFFER } from "@/lib/offer";
import { track } from "@/lib/track";
import { CopyButton, ErrorNote, ToolPanel, fieldLabel } from "./shared";
const PLACEHOLDER = "Paste a product URL, or describe what you're selling and who it's for";
function reelToText(reel: ReelResult): string {
const shots = reel.shots.map((shot, index) => `Shot ${index + 1}: ${shot.line}${shot.visual ? `\n [${shot.visual}]` : ""}`);
return ["HOOKS:", ...reel.hooks.map((hook, index) => `${index + 1}. ${hook}`), "", "3-SHOT OUTLINE:", ...shots].join("\n");
}
function ReelResultView({ reel }: { readonly reel: ReelResult }) {
return (
<div className="mt-6 space-y-6">
<div>
<div className="flex items-center justify-between gap-2">
<h3 className="text-lg font-semibold">{reel.hooks.length} hooks</h3>
<CopyButton text={reel.hooks.join("\n")} label="Copy hooks" />
</div>
<ol className="mt-3 space-y-2">
{reel.hooks.map((hook, index) => (
<li key={hook} className="flex items-start justify-between gap-3 rounded-md border border-border px-3 py-2">
<span><span className="mr-2 text-muted-foreground">{index + 1}.</span>{hook}</span>
<CopyButton text={hook} label="Copy" />
</li>
))}
</ol>
</div>
<div>
<div className="flex items-center justify-between gap-2">
<h3 className="text-lg font-semibold">3-shot script outline</h3>
<CopyButton text={reelToText(reel)} label="Copy outline" />
</div>
<ol className="mt-3 space-y-2">
{reel.shots.map((shot, index) => (
<li key={`${index}-${shot.line.slice(0, 20)}`} className="rounded-md border border-border px-3 py-2">
<p className="text-sm font-semibold text-muted-foreground">Shot {index + 1}</p>
<p>{shot.line}</p>
{shot.visual ? <p className="mt-1 text-sm text-muted-foreground">Show: {shot.visual}</p> : null}
</li>
))}
</ol>
</div>
</div>
);
}
/** Soft upsell matching this tool's exact CTA copy: it reads the live signup offer rather than a hardcoded number. */
function ReelCta() {
return (
<p className="mt-5 rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm text-muted-foreground">
{`Turn this into a voiced, captioned reel. ${OFFER.short}.`}{" "}
<SignedOut>
<Button asChild variant="link" size="sm" className="h-auto p-0 font-semibold">
<Link href="/sign-up" onClick={() => track("signup_click", { source: "reel-hook-generator" })}>
Make the reel <ArrowRight className="size-4" />
</Link>
</Button>
</SignedOut>
<SignedIn>
<Button asChild variant="link" size="sm" className="h-auto p-0 font-semibold">
<Link href="/new">
Make the reel <ArrowRight className="size-4" />
</Link>
</Button>
</SignedIn>
</p>
);
}
export function ReelHookTool() {
const [topic, setTopic] = useState("");
const [platform, setPlatform] = useState<string>("tiktok");
const [tone, setTone] = useState("bold");
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [output, setOutput] = useState<GenerateOutput | null>(null);
const [source, setSource] = useState<"ai" | "template">("ai");
const [seed, setSeed] = useState(1);
/** Offline formula: used when the AI writer is unavailable, and for shuffles. */
function applyTemplate(nextSeed: number): boolean {
const request = validateGenerateRequest({ kind: "reel", topic, platform, tone, lengthSec: 30 });
if (!request.ok) {
setError(request.error);
return false;
}
setOutput(templateOutput(request.value, nextSeed));
setSource("template");
setSeed(nextSeed);
return true;
}
async function submit(event: React.FormEvent) {
event.preventDefault();
setLoading(true);
setError("");
try {
const res = await fetch("/api/tools/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ kind: "reel", topic, platform, tone, lengthSec: 30 }),
});
const data = (await res.json().catch(() => null)) as { ok?: boolean; output?: GenerateOutput; error?: string } | null;
if (res.status === 400 && data?.error) {
setError(data.error);
return;
}
if (!res.ok || !data?.ok || !data.output) {
applyTemplate(seed + 1);
return;
}
setOutput(data.output);
setSource("ai");
} catch {
applyTemplate(seed + 1);
} finally {
setLoading(false);
}
}
return (
<ToolPanel>
<form onSubmit={submit} className="space-y-4">
<div>
<label htmlFor="reel-topic" className={fieldLabel}>Product link or description</label>
<Textarea
id="reel-topic"
value={topic}
onChange={(event) => setTopic(event.target.value)}
placeholder={PLACEHOLDER}
maxLength={MAX_TOPIC_CHARS}
rows={3}
required
/>
<p className="mt-1 text-xs text-muted-foreground">{topic.length}/{MAX_TOPIC_CHARS}</p>
</div>
<div className="grid gap-3 sm:grid-cols-2">
<div>
<label htmlFor="reel-platform" className={fieldLabel}>Platform</label>
<Select id="reel-platform" value={platform} onChange={(event) => setPlatform(event.target.value)}>
<option value="tiktok">TikTok</option>
<option value="reels">Instagram Reels</option>
<option value="shorts">YouTube Shorts</option>
</Select>
</div>
<div>
<label htmlFor="reel-tone" className={fieldLabel}>Tone</label>
<Select id="reel-tone" value={tone} onChange={(event) => setTone(event.target.value)}>
<option value="bold">Bold</option>
<option value="funny">Funny</option>
<option value="educational">Educational</option>
<option value="story">Story</option>
<option value="salesy">Salesy</option>
</Select>
</div>
</div>
<Button type="submit" size="lg" disabled={loading || topic.trim().length < 3}>
{loading ? <Loader2 className="size-4 animate-spin" /> : <Sparkles className="size-4" />}
{loading ? "Writing..." : "Generate hooks + outline"}
</Button>
</form>
{error ? <ErrorNote message={error} /> : null}
{output && output.kind === "reel" ? (
<>
{source === "template" ? (
<div className="mt-5 flex flex-wrap items-center justify-between gap-2 text-sm text-muted-foreground">
<span>Instant hooks and outline from a proven short-form ad structure. Replace the bracketed parts with your specifics.</span>
<Button type="button" variant="outline" size="sm" onClick={() => applyTemplate(seed + 1)}>
<Shuffle className="size-4" /> Shuffle
</Button>
</div>
) : null}
<ReelResultView reel={output.reel} />
<ReelCta />
</>
) : null}
</ToolPanel>
);
}