From 0d924e36ef435a3bb6bd1063c2b67aacfaa4519e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Mon, 15 Jun 2026 20:47:20 -0600 Subject: [PATCH] Replace AI pairings with a deterministic local recommendation engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cart/consultant suggestion carousel no longer depends on Claude-generated pairings. It now computes suggestions locally and instantly from the menu structure + cart — always available, zero API calls, zero cost, no failure point. - New lib/recommendations.ts: getRecommendations(menu, cartItemIds, opts) — a pure function. Section-complement rules (main+no drink -> drinks; food+no dessert -> desserts; drink-only -> food/snacks) classified by flexible keywords (es/en, whole-word match so 'te'/tea doesn't match 'fuertes'), then featured fill (unrepresented sections first, then price desc). Excludes cart items + inactive; empty cart -> featured so the carousel is never empty. - Phase-2 seam: opts.coOccurrence?(cartIds) => Map lets a future market-basket signal blend in WITHOUT changing the carousel — it still only calls getRecommendations(menu, cart). Documented where it plugs in. - PublicMenu computes cartSuggestions via getRecommendations (was the pairings map); carousel shows whenever there's >=1 suggestion and orders are enabled, in both the cart sheet and the consultant. SuggestionCarousel reused unchanged. - Removed the Claude generation: publish no longer calls generatePairings and the 'Generar sugerencias' checkbox is gone; deleted lib/pairings.ts. Restaurant.pairings column kept (unused, no migration churn). i18n parity kept. Glassmorphism/mobile-first/safe-areas untouched. Cart, consultant, SSE, split all intact. Verified (build passes, no Anthropic import in the carousel/publish path): 1 fresh publish (nothing generated) -> carousel shows; 2 main+no drink -> drinks surface first; 3 cart items never suggested; 4 empty cart -> featured; 5 zero Anthropic calls in the carousel flow; 6 carousel in both cart and consultant. --- src/app/api/[slug]/publish/route.ts | 23 +---- src/components/editor/PublishModal.tsx | 17 +--- src/components/public/PublicMenu.tsx | 23 ++--- src/lib/pairings.ts | 72 -------------- src/lib/recommendations.ts | 127 +++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 122 deletions(-) delete mode 100644 src/lib/pairings.ts create mode 100644 src/lib/recommendations.ts diff --git a/src/app/api/[slug]/publish/route.ts b/src/app/api/[slug]/publish/route.ts index d5d5a96..7bf24d3 100644 --- a/src/app/api/[slug]/publish/route.ts +++ b/src/app/api/[slug]/publish/route.ts @@ -1,9 +1,6 @@ import { NextResponse } from 'next/server'; import { requireEditor } from '@/lib/guard'; -import { publishVersion, buildSnapshot } from '@/lib/menu'; -import { generatePairings } from '@/lib/pairings'; - -export const maxDuration = 60; +import { publishVersion } from '@/lib/menu'; export async function POST(req: Request, { params }: { params: { slug: string } }) { const guard = await requireEditor(params.slug); @@ -11,7 +8,6 @@ export async function POST(req: Request, { params }: { params: { slug: string } const body = await req.json().catch(() => null); const versionName = String(body?.versionName ?? '').trim(); - const generateSuggestions = body?.generateSuggestions === true; if (!versionName) return NextResponse.json({ error: 'invalid' }, { status: 400 }); const version = await publishVersion( @@ -20,18 +16,7 @@ export async function POST(req: Request, { params }: { params: { slug: string } guard.restaurant.username, ); - // Optional: regenerate cart pairings from the just-published menu. Never let an - // AI failure break publishing. - let suggestions = false; - if (generateSuggestions) { - try { - const snapshot = await buildSnapshot(guard.restaurant.id); - const result = await generatePairings(guard.restaurant.id, snapshot); - suggestions = result !== null; - } catch (err) { - console.error('publish pairings error', err); - } - } - - return NextResponse.json({ ...version, suggestions }); + // Cart suggestions are now computed locally and deterministically at runtime + // (lib/recommendations.ts) — no AI generation at publish time. + return NextResponse.json(version); } diff --git a/src/components/editor/PublishModal.tsx b/src/components/editor/PublishModal.tsx index be3528a..125ce5c 100644 --- a/src/components/editor/PublishModal.tsx +++ b/src/components/editor/PublishModal.tsx @@ -16,7 +16,6 @@ export default function PublishModal({ const t = useTranslations('editor'); const tc = useTranslations('common'); const [name, setName] = useState(''); - const [suggestions, setSuggestions] = useState(false); const [publishing, setPublishing] = useState(false); const [success, setSuccess] = useState(null); @@ -26,7 +25,7 @@ export default function PublishModal({ try { const res = await api<{ versionName: string }>(slug, '/publish', { method: 'POST', - json: { versionName: name.trim(), generateSuggestions: suggestions }, + json: { versionName: name.trim() }, }); setSuccess(res.versionName); onPublished(res.versionName); @@ -62,20 +61,6 @@ export default function PublishModal({ className="glass-soft rounded-2xl px-4 py-3 outline-none" /> -